[Solved] Call external exe program and pdf generation issue

Java, C++, C#, Delphi, ??? - Using the UNO bridges

[Solved] Call external exe program and pdf generation issue

Postby othmanelmoulat » Tue Nov 27, 2012 1:25 am

hello,
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   Expand viewCollapse view
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();
        }
    }
Last edited by othmanelmoulat on Wed Nov 28, 2012 12:59 am, edited 1 time in total.
OOo 3.4 and LibreOffice 3.4 on openSuse 11.4 + windows 7
othmanelmoulat
 
Posts: 142
Joined: Sun Aug 03, 2008 4:39 am

Re: Call external exe program and pdf generation issue

Postby othmanelmoulat » Tue Nov 27, 2012 6:20 pm

OOo 3.4 and LibreOffice 3.4 on openSuse 11.4 + windows 7
othmanelmoulat
 
Posts: 142
Joined: Sun Aug 03, 2008 4:39 am

Re: Call external exe program and pdf generation issue

Postby othmanelmoulat » Tue Nov 27, 2012 6:39 pm

http://openoffice.2283327.n4.nabble.com ... 74324.html
storeToUrl() is the trouble! can someone suggests how to overcome the issue that cause storeToUrl() to lock the file?
Last edited by othmanelmoulat on Tue Nov 27, 2012 9:52 pm, edited 1 time in total.
OOo 3.4 and LibreOffice 3.4 on openSuse 11.4 + windows 7
othmanelmoulat
 
Posts: 142
Joined: Sun Aug 03, 2008 4:39 am

Re: Call external exe program and pdf generation issue

Postby B Marcelly » Tue Nov 27, 2012 7:48 pm

othmanelmoulat wrote:storeAsUrl() is the trouble! can someone suggests how to overcome the issue that cause storeAsUrl() to lock the file?
:ucrazy:
You must use storeToURL to convert to PDF. And that is what you already do in your code.
The produced PDF is not locked. You can open it in your PDF reader with a double-click.

By program, open the document in your default PDF reader : simply provide the system address (i.e. not the url) of the pdf file as first argument of xSystemShellExecute.execute, and an empty string as second argument.

Remark : if you have installed the extension Oracle PDF Import, this may have caused problems because of your previous attempts with storeAsURL.
Bernard

OpenOffice.org 1.1.5 / Apache OpenOffice 4.1.1 / LibreOffice 5.0.5
MS-Windows 7 Home SP1
B Marcelly
Volunteer
 
Posts: 1160
Joined: Mon Oct 08, 2007 1:26 am
Location: France, Paris area

Re: Call external exe program and pdf generation issue

Postby othmanelmoulat » Tue Nov 27, 2012 9:43 pm

B Marcelly wrote:
othmanelmoulat wrote:storeAsUrl() is the trouble! can someone suggests how to overcome the issue that cause storeAsUrl() to lock the file?
:ucrazy:
You must use storeToURL to convert to PDF. And that is what you already do in your code.
The produced PDF is not locked. You can open it in your PDF reader with a double-click.

By program, open the document in your default PDF reader : simply provide the system address (i.e. not the url) of the pdf file as first argument of xSystemShellExecute.execute, and an empty string as second argument.

Remark : if you have installed the extension Oracle PDF Import, this may have caused problems because of your previous attempts with storeAsURL.

no sorry i mean storeToUrl() is the one causing the trouble not storeAsUrl(). if storetoUrl() is not locking the pdf file then what is the problem in the code that executes the exe program?
OOo 3.4 and LibreOffice 3.4 on openSuse 11.4 + windows 7
othmanelmoulat
 
Posts: 142
Joined: Sun Aug 03, 2008 4:39 am

Re: Call external exe program and pdf generation issue

Postby othmanelmoulat » Wed Nov 28, 2012 12:57 am

ok found my problem:
The problem is that i have another method that generates an xml file using XStream and i was not closing filewriter in exportDocumentAsXML() method so the xml file is locked and this xml file is also used in the exe program. it was the xml file lock causing the problem not the pdf file .
OOo 3.4 and LibreOffice 3.4 on openSuse 11.4 + windows 7
othmanelmoulat
 
Posts: 142
Joined: Sun Aug 03, 2008 4:39 am


Return to External Programs

Who is online

Users browsing this forum: No registered users and 2 guests