i wrote java code to have Openoffice generate a pdf and then after that i use XSystemShellExecute to execute an external exe by giving it as argument the recently generated pdf.
this doesn't work in windows and suspect this b/c openoffice still owns or has a handle for that generated pdf file in some way. so when i try call external exe with this pdf file windows can't proceed b/c the pdf is owned by soffice process.
if my analysis is correct how to tell soffice to release the handle of the generated pdf file.and if my analysis is wrong why the call to external exe doesn't work and makes windows crash?
--Edited---
below are the two methods for exporting pdf and the one for invoking exe program. i suspect the soffice process locks the generated pdf so that when i feed this pdf as arg to exe program windows finds that pdf is locked by another process.
can you propose a solution? or an idea how to overcome this issue?
Code: Select all
public void exportDocumentAsPdf() throws IOException, MalformedURLException, URISyntaxException, java.io.IOException {
String sURL = UnoHelper.getFileUrl( UnoHelper.PDF_FILE_NAME);
PropertyValue[] pdfFilterData = new PropertyValue[3];
pdfFilterData[0] = new PropertyValue();
pdfFilterData[0].Name = "SelectPdfVersion";
pdfFilterData[0].Value = new Integer(1);
pdfFilterData[1] = new PropertyValue();
pdfFilterData[1].Name = "UseTaggedPDF";
pdfFilterData[1].Value = new Boolean("true");
pdfFilterData[2] = new PropertyValue();
pdfFilterData[2].Name = "PageRange";
int pages = (pageCount > 1) ? (pageCount - 1) : pageCount;
pdfFilterData[2].Value = "1-" + pages;
PropertyValue[] conversionProperties = new PropertyValue[2];
conversionProperties[0] = new PropertyValue();
conversionProperties[0].Name = "FilterName";
conversionProperties[0].Value = "writer_pdf_Export";
conversionProperties[1] = new PropertyValue();
conversionProperties[1].Name = "FilterData";
conversionProperties[1].Value = pdfFilterData;
XStorable xStorable = (XStorable) UnoRuntime.queryInterface(
XStorable.class, m_xComponent);
// XStorable.storeToURL() expects an URL telling where to store the document and an array of PropertyValue indicating how to store it
xStorable.storeToURL(sURL, conversionProperties);
//print log message
URL url = new URL(sURL);
pdfFile = new File(url.toURI());
this.message.append("\n\nDocument Exported To pdf/A File : " + pdfFile.getCanonicalPath() + "\n\n");
log.println(message);
}
public void invokeProgram(XMultiComponentFactory mxMCF, XComponentContext m_xContext) {
try {
// open the help web page
final Object xObject = mxMCF.createInstanceWithContext("com.sun.star.system.SystemShellExecute", m_xContext);
final XSystemShellExecute xSystemShellExecute = (XSystemShellExecute) UnoRuntime.queryInterface(XSystemShellExecute.class, xObject);
File programDir = new File(XPreferences.getInstance().getPrintServerDir());
String programPath = programDir.toURI().getPath().substring(1)+UnoHelper.EXE_FILE_NAME;
String arg=pdfFile.toURI().getPath().substring(1);
log.println("program path: " + programPath);
log.println("pdf path: " + arg);
if (xSystemShellExecute != null) {
xSystemShellExecute.execute(programPath, arg, SystemShellExecuteFlags.DEFAULTS);
}
} catch (Exception ex) {
ex.printStackTrace();
}
}