Thanks for the tip. I've inserted the following between the load and
save - it appears to work:
XTextFieldsSupplier supplier = (XTextFieldsSupplier)
UnoRuntime.queryInterface(XTextFieldsSupplier.class, document);
XEnumerationAccess fields = supplier.getTextFields();
XRefreshable refreshable = (XRefreshable)
UnoRuntime.queryInterface(XRefreshable.class, fields);
refreshable.refresh();
Is there an explanation for why this works?
Thanks,
Tim
Kent Gibson wrote:
also, I believe that user fields themselves support
the XRefreshable interface, so you might just try
refreshing the user fields, instead of the whole
document.
--- Tim Anderson <[EMAIL PROTECTED]> wrote:
(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]