4

I have a ColdFusion application that reads a list of files from a directory, and then converts each MSOffice document in the list to a PDF using the JODConverter library and OpenOffice.org 3.4.1.

I wrote this application and setup my development PC according the instructions in the two articles here:

http://cfsearching.blogspot.com/search/label/JODConverter

The only difference is that I installed the necessary JARs outside of cf_root.

<cffunction name="convertNonPDFFiles" returntype="Void" output="false">
    <cfscript>
        //  CONSTANTs
        var _NON_PDF_PATH = APPLICATION.PDFSource & "\NonPDFs";
        var _PDF_PATH = APPLICATION.PDFSource & "\PDFs";
        var _VALID_FILE_EXTENSIONS = "doc,docx,ppt,pptx";

        //  Set defaults for private variables
        var _qNonPDFDir = QueryNew("");
        var _fileName = "";
        var _documentId = 0;
        var _sourceFilePath = "";
        var _destinationFilePath = "";
        var _fileExtension = "";
        var _isConversionSuccessful = true;
        var _tempSourceFilePath = "";
        var _tempImageFilePath = "";

        //  Initialize Open Office Conversion Manager
        var _openOfficeManager =
            CreateObject(
                "java",
                "org.artofsolving.jodconverter.office.DefaultOfficeManagerConfiguration"
                ).setOfficeHome(
                    APPLICATION.OpenOfficeProgramPath // Location of the OpenOffice.org 3.4.1 application directory on the server
                    ).setTaskExecutionTimeout(60000).buildOfficeManager();

        _openOfficeManager.start();
    </cfscript>

    <!--- Retrieve a list of file names in the directory of unprocessed
        non-PDF files --->
    <cfdirectory
        action="list"
        directory="#_NON_PDF_PATH#"
        name="_qNonPDFDir"
        type="file"
        listinfo="name"
        sort="datelastmodified DESC" />

    <cfoutput query="_qNonPDFDir">
        <cfscript>
            _fileName = _qNonPDFDir.name;
            _fileExtension =
                REQUEST.UDFLib.File.getFileExtension(_fileName);
            _sourceFilePath = _NON_PDF_PATH & "\" & _fileName;

            //  File is a valid format for conversion
            if  (ListFindNoCase(_VALID_FILE_EXTENSIONS, _fileExtension)) {
                _documentId =
                    REQUEST.UDFLib.File.getFileNameWithoutExtension(
                        _fileName
                        );
                _destinationFilePath =
                        _PDF_PATH
                    &   "\"
                    &   REQUEST.UDFLib.File.getFileNameWithoutExtension(
                            _fileName
                            )
                    &   ".pdf";
                _isConversionSuccessful = true;
                _tempSourceFilePath =
                        APPLICATION.TempDir
                    &   "\"
                    &   _documentId
                    &   "." & _fileExtension;

                /*
                    Create of the copy of the original file in the temp
                    directory
                */
                FileCopy(
                    APPLICATION.of_aprimo_root & "\" & _documentId & ".dat",
                    _tempSourceFilePath
                    );

                //  Attempt to convert the file to PDF
                try {
                    // See convertFile() method below
                    convertFile(
                        openOfficeManager = _openOfficeManager,
                        inputFilePath = _tempSourceFilePath,
                        outputFilePath = _destinationFilePath
                        );
                }
                catch (any e) {
                    _isConversionSuccessful = false;
                }

                if  (_isConversionSuccessful)
                    FileMove(
                        _sourceFilePath,
                        _NON_PDF_PATH & "\Processed\"
                        );
                else
                    FileMove(
                        _sourceFilePath,
                        _NON_PDF_PATH & "\NonFunctioning\"
                        );
            }
            //  File is not a valid format for conversion
            else {
                FileDelete(_sourceFilePath);
            }
        </cfscript>
    </cfoutput>

    <cfscript>
        _openOfficeManager.stop();

        return;
    </cfscript>
</cffunction>

<cfscript>
    function convertFile(openOfficeManager, inputFilePath, outputFilePath) {
        CreateObject(
            "java",
            "org.artofsolving.jodconverter.OfficeDocumentConverter"
            ).init(ARGUMENTS.OpenOfficeManager).convert(
                CreateObject(
                    "java",
                    "java.io.File"
                    ).init(ARGUMENTS.inputFilePath),
                CreateObject(
                    "java",
                    "java.io.File"
                    ).init(ARGUMENTS.outputFilePath)
                );

        return;
    }
</cfscript>

This application works perfectly on my development machine, but as soon as I move it to one of my web servers, it doesn't work there.

Dev PC Setup:

 OS: Windows 7 Professional SP1
 IIS: 7
 ColdFusion: 8.0.1

Server Setup:

 OS: Windows 2003 R2 Standard Edition SP2
 IIS: 6.0
 ColdFusion: 8.0.1

When I attempt to run the application on the server - either directly in a browser or via Scheduled Tasks, it throws no exceptions. It simply appears to run until it times out after 60 minutes. In Task Manager, I can see soffice.bin start running when the application starts, but after a few seconds, soffice.bin simply disappears from the Task Manager.

Any ideas what might be the problem?

Eric Belair
  • 10,574
  • 13
  • 75
  • 116
  • Have you checked to make sure `APPLICATION.OpenOfficeProgramPath` is the same in both environments? – Lance Jul 05 '13 at 20:34
  • @Lance, Yes, I have and it's a config setting that is set differently in both environments. I have confirmed that the OpenOfficeManager object is correctly instantiated, but when it calls start(), it just never comes back.... – Eric Belair Jul 05 '13 at 20:40
  • It sounds like there may be a problem connecting. What do the logs files say? Also, does the jodconverter work at all on that machine - for example from the command line? – Leigh Jul 09 '13 at 02:55

2 Answers2

1

After some troubleshooting, I was finally able to get this to work with a few minor changes to the programming (all credit to cfSearching - I found the answer to my problem in the comments at http://cfsearching.blogspot.com/search/label/JODConverter).

Original code that configured and started the OpenOfficeManager instance:

            CreateObject(
                "java",
                "org.artofsolving.jodconverter.office.DefaultOfficeManagerConfiguration"
                ).setOfficeHome(
                    APPLICATION.OpenOfficeProgramPath
                    ).setTaskExecutionTimeout(60000).buildOfficeManager();

Updated (fixed) to add setConnectionProtocol() and setPortNumber():

            CreateObject(
                "java",
                "org.artofsolving.jodconverter.office.DefaultOfficeManagerConfiguration"
                ).setOfficeHome(
                    APPLICATION.OpenOfficeProgramPath
                    ).setConnectionProtocol(
                        CreateObject(
                            "java",
                            "org.artofsolving.jodconverter.office.OfficeConnectionProtocol"
                            ).SOCKET
                        ).setPortNumber(
                            8100
                            ).setTaskExecutionTimeout(
                                60000
                                ).buildOfficeManager();
Eric Belair
  • 10,574
  • 13
  • 75
  • 116
0

It may be as simple as OpenOffice needing to be re-installed on the server where as it is on your dev machine.

Jas Panesar
  • 6,597
  • 3
  • 36
  • 47
  • The install looks good. I actually installed it on two other servers that are configured similarly (a QA and UAT server) and restarted all three servers, and the production box is the only one that caused a problem. – Eric Belair Jul 09 '13 at 12:24