(Originally posted at http://www.oooforum.org/forum/viewtopic.phtml?t=41056)

I'm using OpenOffice 2.0.3 to convert ODT byte streams to PDF from a
servlet.
However, the PDF generation doesn't work correctly unless I introduce a
sleep() between the call to loadComponentFromURL() and storeToURL().

Without the sleep(), a blank page is inserted, and text from the start
of the document is missing.

The source document includes user fields, which aren't manipulated
during the conversion.
The document is ~8K in size, and I'm using a socket connection.
From the forum discussion, the issue seems to be related to the fact
that the document has user fields.
Can anyone confirm if this is a bug, or suggest a workaround that
doesn't involve using sleep()?

Thanks,

Tim

Conversion code is as follows:

       XComponentLoader loader = // get loader
       byte[] content =                      // get ODT content
       XInputStream inputStream = new
ByteArrayToXInputStreamAdapter(content);
       PropertyValue[] properties = new PropertyValue[]{
               newProperty("ReadOnly", true),
               newProperty("Hidden", true),
               newProperty("AsTemplate", true),
               newProperty("InputStream", inputStream)
       };

       XComponent component =
loader.loadComponentFromURL("private:stream", "_blank", 0, properties);

       Thread.sleep(1000);   // required to produce correct PDF

       XTextDocument textDocument = (XTextDocument)
UnoRuntime.queryInterface(XTextDocument.class, component);
       XOutputStreamToByteArrayAdapter outputStream = new
XOutputStreamToByteArrayAdapter();

       XStorable storable = (XStorable)
UnoRuntime.queryInterface(XStorable.class, textDocument);

       properties = new PropertyValue[]{
               newProperty("OutputStream", outputStream),
               newProperty("Overwrite", true),
               newProperty("FilterName", "writer_pdf_Export")
       };

       storable.storeToURL("private:stream", properties);
       outputStream.closeOutput();

       byte[] pdfContent = outputStream.getBuffer();

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to