List Info

Thread: ODT to PDF export incorrect, unless Thread.sleep() used




ODT to PDF export incorrect, unless Thread.sleep() used
user name
2006-08-16 21:26:28
(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: dev-unsubscribeapi.openoffice.org
For additional commands, e-mail: dev-helpapi.openoffice.org

ODT to PDF export incorrect, unless Thread.sleep() used
user name
2006-08-17 06:07:33
I have had similiar problems with pdfs, but with
chained frames coming out wrong. 

By using the refresh, and/or the
xTextDocument.reformat, at strategic locations (for
exampel after an insertcontent) I often have better
results.

--- Tim Anderson <tmanetspace.net.au> 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:
> dev-unsubscribeapi.openoffice.org
> For additional commands, e-mail:
> dev-helpapi.openoffice.org
> 
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection
around 
http://mail.yahoo.com 

------------------------------------------------------------
---------
To unsubscribe, e-mail: dev-unsubscribeapi.openoffice.org
For additional commands, e-mail: dev-helpapi.openoffice.org

ODT to PDF export incorrect, unless Thread.sleep() used
user name
2006-08-17 06:11:00
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 <tmanetspace.net.au> 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:
> dev-unsubscribeapi.openoffice.org
> For additional commands, e-mail:
> dev-helpapi.openoffice.org
> 
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection
around 
http://mail.yahoo.com 

------------------------------------------------------------
---------
To unsubscribe, e-mail: dev-unsubscribeapi.openoffice.org
For additional commands, e-mail: dev-helpapi.openoffice.org

ODT to PDF export incorrect, unless Thread.sleep() used
user name
2006-08-24 22:18:14
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 <tmanetspace.net.au> 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: dev-unsubscribeapi.openoffice.org
For additional commands, e-mail: dev-helpapi.openoffice.org

ODT to PDF export incorrect, unless Thread.sleep() used
user name
2006-08-25 10:00:50
in your case I believe it is logical. Text fields
require refreshment in order to have their actual
results. I really don't know I have never used next
fields but the example in the developers guide
refreshes them.

However what I would like to know is what refresh or
reformat does at the document level.

--- Tim Anderson <tmanetspace.net.au> wrote:

> 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 <tmanetspace.net.au> 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:
> dev-unsubscribeapi.openoffice.org
> For additional commands, e-mail:
> dev-helpapi.openoffice.org
> 
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection
around 
http://mail.yahoo.com 

------------------------------------------------------------
---------
To unsubscribe, e-mail: dev-unsubscribeapi.openoffice.org
For additional commands, e-mail: dev-helpapi.openoffice.org

ODT to PDF export incorrect, unless Thread.sleep() used
user name
2006-08-25 10:00:50
in your case I believe it is logical. Text fields
require refreshment in order to have their actual
results. I really don't know I have never used next
fields but the example in the developers guide
refreshes them.

However what I would like to know is what refresh or
reformat does at the document level.

--- Tim Anderson <tmanetspace.net.au> wrote:

> 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 <tmanetspace.net.au> 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:
> dev-unsubscribeapi.openoffice.org
> For additional commands, e-mail:
> dev-helpapi.openoffice.org
> 
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection
around 
http://mail.yahoo.com 

------------------------------------------------------------
---------
To unsubscribe, e-mail: dev-unsubscribeapi.openoffice.org
For additional commands, e-mail: dev-helpapi.openoffice.org

ODT to PDF export incorrect, unless Thread.sleep() used
user name
2006-08-25 17:24:35
Tim Anderson wrote:

> 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?

It seems that there are some necessary updates to be done
after loading
and for performance reasons they usually are done in the
background.
IMHO even then there should be some code for forcing these
updates in
those cases where they should be up to date, but obviously
this doesn't
happen. I consider this to be a bug.

If the Writer uses asynchronous updating procedures and OTOH
has some
API calls that require updated objects prior to their
execution (like
PDF export or printing) there should be a trigger that these
API calls
can use to force all pending updeates (that of course should
be
registered there before).

Best regards,
Mathias

-- 
Mathias Bauer - OpenOffice.org Application Framework Project
Lead
Please reply to the list only, nospamforMBAgmx.de is
a spam sink.

------------------------------------------------------------
---------
To unsubscribe, e-mail: dev-unsubscribeapi.openoffice.org
For additional commands, e-mail: dev-helpapi.openoffice.org

[1-7]

about | contact  Other archives ( Real Estate discussion Medical topics )