Using pdf output filters from Java

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Using pdf output filters from Java

paul.edmondson
Hi,

I'm having problems saving documents using the various PDF output  
filters from a Java servlet and after reading through all the  
examples and various questions I've become stuck and would like some  
help or advice from the OOo experts.

I can save MS Word and OOo Writer files as HTML but not as PDF.

I am using the following environment:-

- OpenOffice 2.0.2
- Debian etch (x86_64)
- JDK-1.5.0_06
- tomcat 5.5.17
- CLASSPATH (set within $CATALINA_HOME/bin/setclasspath.sh) /usr/lib/
openoffice/program/classes/juh.jar:/usr/lib/openoffice/program/
classes/jurt.jar:/usr/lib/openoffice/program/classes/ridl.jar:/usr/
lib/openoffice/program/classes/unoloader.jar:/usr/lib/openoffice/
program/classes/unoil.jar:/usr/lib/openoffice/program
- Using Xvfb

The snippet of code that creates the PDF files is as follows. (Most  
of this is adapted from the ConverterServlet in the examples folder  
for the SDK together with parts adapted from ooo-cgi):-

        // Getting an object that will offer a simple way to store a  
document to a URL.
             XStorable xstorable = (XStorable)
UnoRuntime.queryInterface(XStorable.class, objectDocumentToStore);

        // List of output filters from ooo-cgi (HTML added for testing other  
formats.)
             String[] pdfFormats = {"writer_pdf_Export",  
"writer_web_pdf_Export",
                         "writer_globaldocument_pdf_Export",  
"calc_pdf_Export",
                         "impress_pdf_Export", "draw_pdf_Export",  
"math_pdf_Export", "HTML (StarWriter)"};
             // Preparing properties for converting the document
             propertyvalue = new PropertyValue[1];
             for(int i = 0; i < pdfFormats.length; i++) {
                 propertyvalue[0] = new PropertyValue();
                 propertyvalue[0].Name = "FilterName";
                 propertyvalue[0].Value = pdfFormats[i];

                 // Storing and converting the document
                 try {
                     xstorable.storeToURL(filePrefix +  
convertedFile.toString(), propertyvalue);
                     debugLog.debug("Document saved in this format: "  
+ pdfFormats[i]);
                     break;
                 } catch (Exception e) {
                     debugLog.debug("Document not saved in this  
format: " + pdfFormats[i], e);
                 }
             }

             XCloseable xcloseable = (XCloseable)
UnoRuntime.queryInterface(XCloseable.class, xstorable);

             // Closing the converted document
             if (xcloseable != null) {
                 xcloseable.close(false);
             } else {
                 // If Xcloseable is not supported (older versions,
                 // use dispose() for closing the document
                 XComponent xComponent = (XComponent)
UnoRuntime.queryInterface(XComponent.class, xstorable);
                 xComponent.dispose();
             }


For every PDF filter type a com.sun.star.task.ErrorCodeIOException is  
thrown but not when using the "HTML (StarWriter)" filter.

Is there something obvious that I'm missing? Do I need to add any  
extra jars to the classpath?


Thanks in advance for any help or advice.



Paul Edmondson.


 

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Using pdf output filters from Java

Stephan Wunderlich - Sun Germany - ham02 - Hamburg
Hi Paul,

> For every PDF filter type a com.sun.star.task.ErrorCodeIOException is  
> thrown but not when using the "HTML (StarWriter)" filter.
>
> Is there something obvious that I'm missing? Do I need to add any  extra
> jars to the classpath?

if you opened the documents you plan to store to PDF in "hidden" mode
than this is a known issue which will be fixed in OOo 2.0.3 ... as a
workaround you could open your documents visible before converting them.

Hope that helps

Regards

Stephan

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Using pdf output filters from Java

Tom Schindl
In reply to this post by paul.edmondson
A good starting point might be here:
http://codesnippets.services.openoffice.org/Office/Office.ConvertDocuments.snip

Tom

Paul Edmondson wrote:

> Hi,
>
> I'm having problems saving documents using the various PDF output
> filters from a Java servlet and after reading through all the  examples
> and various questions I've become stuck and would like some  help or
> advice from the OOo experts.
>
> I can save MS Word and OOo Writer files as HTML but not as PDF.
>
> I am using the following environment:-
>
> - OpenOffice 2.0.2
> - Debian etch (x86_64)
> - JDK-1.5.0_06
> - tomcat 5.5.17
> - CLASSPATH (set within $CATALINA_HOME/bin/setclasspath.sh) /usr/lib/
> openoffice/program/classes/juh.jar:/usr/lib/openoffice/program/
> classes/jurt.jar:/usr/lib/openoffice/program/classes/ridl.jar:/usr/
> lib/openoffice/program/classes/unoloader.jar:/usr/lib/openoffice/
> program/classes/unoil.jar:/usr/lib/openoffice/program
> - Using Xvfb
>
> The snippet of code that creates the PDF files is as follows. (Most  of
> this is adapted from the ConverterServlet in the examples folder  for
> the SDK together with parts adapted from ooo-cgi):-
>
>     // Getting an object that will offer a simple way to store a
> document to a URL.
>             XStorable xstorable = (XStorable)
> UnoRuntime.queryInterface(XStorable.class, objectDocumentToStore);
>
>     // List of output filters from ooo-cgi (HTML added for testing
> other  formats.)
>             String[] pdfFormats = {"writer_pdf_Export",
> "writer_web_pdf_Export",
>                         "writer_globaldocument_pdf_Export",
> "calc_pdf_Export",
>                         "impress_pdf_Export", "draw_pdf_Export",
> "math_pdf_Export", "HTML (StarWriter)"};
>             // Preparing properties for converting the document
>             propertyvalue = new PropertyValue[1];
>             for(int i = 0; i < pdfFormats.length; i++) {
>                 propertyvalue[0] = new PropertyValue();
>                 propertyvalue[0].Name = "FilterName";
>                 propertyvalue[0].Value = pdfFormats[i];
>
>                 // Storing and converting the document
>                 try {
>                     xstorable.storeToURL(filePrefix +
> convertedFile.toString(), propertyvalue);
>                     debugLog.debug("Document saved in this format: "  +
> pdfFormats[i]);
>                     break;
>                 } catch (Exception e) {
>                     debugLog.debug("Document not saved in this  format:
> " + pdfFormats[i], e);
>                 }
>             }
>
>             XCloseable xcloseable = (XCloseable)
> UnoRuntime.queryInterface(XCloseable.class, xstorable);
>
>             // Closing the converted document
>             if (xcloseable != null) {
>                 xcloseable.close(false);
>             } else {
>                 // If Xcloseable is not supported (older versions,
>                 // use dispose() for closing the document
>                 XComponent xComponent = (XComponent)
> UnoRuntime.queryInterface(XComponent.class, xstorable);
>                 xComponent.dispose();
>             }
>
>
> For every PDF filter type a com.sun.star.task.ErrorCodeIOException is
> thrown but not when using the "HTML (StarWriter)" filter.
>
> Is there something obvious that I'm missing? Do I need to add any  extra
> jars to the classpath?
>
>
> Thanks in advance for any help or advice.
>
>
>
> Paul Edmondson.
>
>
>  
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>

Reply | Threaded
Open this post in threaded view
|

RE: Using pdf output filters from Java

Yeatts, Garnett W. CONTR J9C329
In reply to this post by paul.edmondson
Paul,
       
        It looks like you are trying to loop through mix-matched
filters.  Do you know what type of document you are dealing with?  I
think the filters need to be matched to the document type, but you are
trying to apply different filter types (calc, text, draw and impress) to
a single document.  

        Another possible problem may be that once you store it as
another type - your original xStorage may be converted to the new type.
I am not certain about this one - but keep it in mind.

        I am doing something very similar - see my attached file.  I
have gotten similar errors when I mix-match files/filters (such as when
users use incorrect file extension which causes me to pick the wrong
filter).

        Good luck.

Garnett

-----Original Message-----
From: Paul Edmondson [mailto:[hidden email]]
Sent: Wednesday, May 03, 2006 10:09 AM
To: [hidden email]
Subject: [dev] Using pdf output filters from Java

Hi,

I'm having problems saving documents using the various PDF output  
filters from a Java servlet and after reading through all the  
examples and various questions I've become stuck and would like some  
help or advice from the OOo experts.

I can save MS Word and OOo Writer files as HTML but not as PDF.

I am using the following environment:-

- OpenOffice 2.0.2
- Debian etch (x86_64)
- JDK-1.5.0_06
- tomcat 5.5.17
- CLASSPATH (set within $CATALINA_HOME/bin/setclasspath.sh) /usr/lib/
openoffice/program/classes/juh.jar:/usr/lib/openoffice/program/
classes/jurt.jar:/usr/lib/openoffice/program/classes/ridl.jar:/usr/
lib/openoffice/program/classes/unoloader.jar:/usr/lib/openoffice/
program/classes/unoil.jar:/usr/lib/openoffice/program
- Using Xvfb

The snippet of code that creates the PDF files is as follows. (Most  
of this is adapted from the ConverterServlet in the examples folder  
for the SDK together with parts adapted from ooo-cgi):-

        // Getting an object that will offer a simple way to store a  
document to a URL.
             XStorable xstorable = (XStorable)
UnoRuntime.queryInterface(XStorable.class, objectDocumentToStore);

        // List of output filters from ooo-cgi (HTML added for testing
other  
formats.)
             String[] pdfFormats = {"writer_pdf_Export",  
"writer_web_pdf_Export",
                         "writer_globaldocument_pdf_Export",  
"calc_pdf_Export",
                         "impress_pdf_Export", "draw_pdf_Export",  
"math_pdf_Export", "HTML (StarWriter)"};
             // Preparing properties for converting the document
             propertyvalue = new PropertyValue[1];
             for(int i = 0; i < pdfFormats.length; i++) {
                 propertyvalue[0] = new PropertyValue();
                 propertyvalue[0].Name = "FilterName";
                 propertyvalue[0].Value = pdfFormats[i];

                 // Storing and converting the document
                 try {
                     xstorable.storeToURL(filePrefix +  
convertedFile.toString(), propertyvalue);
                     debugLog.debug("Document saved in this format: "  
+ pdfFormats[i]);
                     break;
                 } catch (Exception e) {
                     debugLog.debug("Document not saved in this  
format: " + pdfFormats[i], e);
                 }
             }

             XCloseable xcloseable = (XCloseable)
UnoRuntime.queryInterface(XCloseable.class, xstorable);

             // Closing the converted document
             if (xcloseable != null) {
                 xcloseable.close(false);
             } else {
                 // If Xcloseable is not supported (older versions,
                 // use dispose() for closing the document
                 XComponent xComponent = (XComponent)
UnoRuntime.queryInterface(XComponent.class, xstorable);
                 xComponent.dispose();
             }


For every PDF filter type a com.sun.star.task.ErrorCodeIOException is  
thrown but not when using the "HTML (StarWriter)" filter.

Is there something obvious that I'm missing? Do I need to add any  
extra jars to the classpath?


Thanks in advance for any help or advice.



Paul Edmondson.


 

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Using pdf output filters from Java

paul.edmondson
In reply to this post by Stephan Wunderlich - Sun Germany - ham02 - Hamburg
Thanks everyone for all the help and advice.

The workaround that Stephan provided is working for now. I guess I'll  
have to wait for 2.0.3 to be able to run in hidden mode.

On 3 May 2006, at 15:34, Stephan Wunderlich wrote:

>
> if you opened the documents you plan to store to PDF in "hidden"  
> mode than this is a known issue which will be fixed in OOo  
> 2.0.3 ... as a workaround you could open your documents visible  
> before converting them.
>
> Hope that helps
>
> Regards
>
> Stephan


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Using pdf output filters from Java

paul.edmondson
In reply to this post by Yeatts, Garnett W. CONTR J9C329

On 3 May 2006, at 16:38, Yeatts, Garnett W. CONTR J9C329 wrote:

> Paul,
>
> It looks like you are trying to loop through mix-matched
> filters.  Do you know what type of document you are dealing with?  I
> think the filters need to be matched to the document type, but you are
> trying to apply different filter types (calc, text, draw and  
> impress) to
> a single document.

I know it looks a little messy but I was looping through just trying  
to get anything out.
Now I'm actually getting some converted files out I'll apply the more  
appropriate filter.
>
> Another possible problem may be that once you store it as
> another type - your original xStorage may be converted to the new  
> type.
> I am not certain about this one - but keep it in mind.
>
Thanks for the heads up on this one. I'll keep a look out for it.

> I am doing something very similar - see my attached file.  I
> have gotten similar errors when I mix-match files/filters (such as  
> when
> users use incorrect file extension which causes me to pick the wrong
> filter).
>
> Good luck.
>
> Garnett
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]