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?