Sign in to follow this  
Followers 0
john renfrew

A doc and docx convertor to PDF

5 posts in this topic

Small offering from today's work

http://code.google.com/jodconverter/

Just got this to work on a PC to convert both doc and docx files to PDF, AND xls and xlsx adn csv

You need Open Office installed, and I tell it where this is as I use a non-standard location

but should therefore work just as well on Mac

You need all the jars loaded from the download but works a real treat - no need to have Open Office even open so silent as far as the user is concerned

Just prints with default settings, so next thing is to work out you how to change paper size etc.


// DocxToPDF ( fm_fileIn ; fm_fileOut ; officeHome )

// 12_02_22 JR

// v1.0

//

// officeHome is path to OpenOffice executable

// http://code.google.com/p/jodconverter/

// requires all jar files from download to be loaded



import org.artofsolving.jodconverter.office.DefaultOfficeManagerConfiguration

import org.artofsolving.jodconverter.OfficeDocumentConverter



officeManager = new DefaultOfficeManagerConfiguration().setOfficeHome(officeHome).buildOfficeManager()

officeManager.start()

converter = new OfficeDocumentConverter(officeManager)

try{

    converter.convert(new File(fm_fileIn), new File(fm_fileOut))

    result = ''

} catch (e){result = e.getMessage()}

officeManager.stop()

if(result) {

return result

} else {

return true

}



Share this post


Link to post
Share on other sites

Hey John,

I'm trying to address the same problem, I want a Filemaker Script (on a Mac) that basically converts a Word-Document to a PDF Document in the background, both Documents are stored in a separate SuperContainer location.

I got this to run with jodconverter that I invoke with a command line java command. Problem is: This solution opens OpenOffice, so it does not run silent at all.

How can I get your approach to run? Do I need to save your file as a java program, then call your .jar instead of jodconverter.jar?

Thanks!

Share this post


Link to post
Share on other sites

Hmmm

Went back and looked at this

This is v2.2.2, haven't yet got version 3 working on Mac as I cant find a way to pass the function a path which is inside the .app package of OpenOffice ( and it is not being maintained any more according to the author ) It works on Windows with a path like d:/OpenOffice

Try this code instead


//DoctoPDF ( fm_fileIn ; fm_fileOut )

//



import com.artofsolving.jodconverter.*

import com.artofsolving.jodconverter.openoffice.connection.*

import com.artofsolving.jodconverter.openoffice.converter.*

import com.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection



input = new File(fm_fileIn)

output = new File(fm_fileOut)

connection = new SocketOpenOfficeConnection(8100)

connection.connect()

registry = new DefaultDocumentFormatRegistry()

converter = new OpenOfficeDocumentConverter(connection, registry)

pdf = registry.getFormatByFileExtension("pdf")

pdfOptions = [ 'ReduceImageResolution': true, 'MaxImageResolution': 300 ]

pdf.setExportOption(DocumentFamily.TEXT, "FilterData", pdfOptions)

try {

converter.convert(input, output, pdf)

result = ''

} catch (e){result = e.getMessage()}

connection.disconnect()

if ( result ) {

return result

} else {

return true

}







First of all OpenOffice needs to be started in headless mode from the command line though. That just means it doesnt pop up each time you use it, but it does need to run in the background

Just tried it on a new Lion Mac with this and it works with the latest download



"/Volumes/Macintosh HD/Applications/OpenOffice.org.app/Contents/MacOS/soffice.bin" -headless -nofirststartwizard -accept="socket,host=localhost,port=8100;urp;StarOffice.Service"

Instructions at http://community.nux...openoffice.html section 46.1.1

Then the following jars need loading (from the zip at http://sourceforge.n...onverter/files/ )

Commons-io-1.4

Jodconverter-2.2.2

Juh-3.2.1

Jurt-3.2.1

Ridl-3.2.1

Slf4j-Api-1.6.1

Unoil-3.2.1

(Xstream-1.3.1 ??)

If anyone knows how to pass a path from inside a package to SM that would be a lovley thing

Share this post


Link to post
Share on other sites

Actually fixed it

The first lines of the first example should be:




import org.artofsolving.jodconverter.office.DefaultOfficeManagerConfiguration

import org.artofsolving.jodconverter.OfficeDocumentConverter

import org.artofsolving.jodconverter.*

import org.artofsolving.jodconverter.office.OfficeUtils

import org.artofsolving.jodconverter.document.DocumentFormat

import org.artofsolving.jodconverter.document.DocumentFamily

import org.artofsolving.jodconverter.util.PlatformUtils

import org.artofsolving.jodconverter.StandardConversionTask



if ( PlatformUtils.isMac() ){

//change this to location of applications folder

oHome = new File ('/Volumes/Macintosh HD/Applications/OpenOffice.org.app/Contents/')

} else oHome = officeHome



officeManager = new DefaultOfficeManagerConfiguration().setOfficeHome(oHome).buildOfficeManager()



This will start OpenOffice, create the PDF then close it

So this needs the 3.0 beta 4 version of jodconverter

Share this post


Link to post
Share on other sites

Wow - this was real faaaast! I'll have to try and make this work. I have the 3.0 beta 4 version, so I hope I'll be good.

Thanx, I'll let you know how this went..

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0