| View previous topic :: View next topic |
| Author |
Message |
baptux Guest
|
Posted: Thu Jun 19, 2003 8:57 am Post subject: unable to convert Document to PDF with UNO and JAVA |
|
|
I'm currently writing a software in java that should be able to convert to document from/to multiple format, even exporting to PDF
I'm using OOo1.1beta2, with the 1.1beta2 SDK, on Linux, and java 1.4.1 and I'm not able to convert any document to pdf, all other formats I need are ok, but not PDF.
I've read the past topic about the same problem, but nothing in this topic helps me to make it work
If someone get it working, can post the way he got that.
In my test the DocumentConverter example doesn't work either. |
|
| Back to top |
|
 |
rubier Newbie

Joined: 20 Jun 2003 Posts: 1
|
Posted: Fri Jun 20, 2003 8:43 am Post subject: How to convert a sxw file to pdf file with sdk 1.1 beta2 |
|
|
In first, excuse me for my bad english.
I am using java api since 1.0.2 around writter. And i cannot see how to export a sxw file to a pdf file. I load a template, i replace text, i save the new document to sxw format and i use the acrobatdistiller OK!
Since 1.1b2 it is possible to export to pdf directly. Is this method better than acrobatdistiller? and if yes there everyone who can give me a sample?
thank you |
|
| Back to top |
|
 |
zoddo Guest
|
Posted: Fri Jul 04, 2003 6:36 am Post subject: how can you do that? |
|
|
| Quote: | . I load a template, i replace text, i save the new document to sxw format and i use the acrobatdistiller OK!
|
Can you send me the code that does this operation?
Thanks in advance.
ronchi @ csr.unibo.it (delete the spaces I've putted against spam) |
|
| Back to top |
|
 |
AfinitySix General User

Joined: 05 Jul 2003 Posts: 9 Location: Malaysia
|
Posted: Sat Jul 05, 2003 3:24 am Post subject: PDF Generation |
|
|
Generating PDF Documents via OpenOffice.org was never possible until the 1.1 Beta version.
I assume you have gone through the Developer's samples about Document Handling, and you are familar with the XInterface concepts.
I will no go through the details about obtaining an XTextDocument instance.
The codes used to generate PDF are as follows:
| Code: |
try {
XTextDocument document = ... //This is where you get the XTextDocument
XModel xModel = (XModel)UnoRuntime.queryInterface(XModel.class, document);
XFrame xFrame = xModel.getCurrentController().getFrame();
xFrame.activate();
XStorable xStorable = (XStorable)UnoRuntime.queryInterface(XStorable.class, document);
PropertyValue[] props = new PropertyValue[2];
props[0] = new PropertyValue();
props[0].Name = "FilterName";
props[0].Value = "writer_pdf_Export";
props[1] = new PropertyValue();
props[1].Name = "CompressionMode";
props[1].Value = "1";
String tURL = "file:///D:/GeneratedDocs/PDFTest.pdf";
xStorable.storeToURL(tURL, props);
} catch (Exception ex) {
//Exception handling goes here
}
|
This code snipet simply shows an example of storing an XTextDocument in PDF format, to a target URL specified by tURL. The main point to note is that you have to activate the XFrame in order to generate the PDF Document (refer to code).
The Property sets are simply used to tell the XStorable interface about how the XTextDocument is to be stored. In this case, we simply use the writer_pdf_Export filter to save the file as.
Good luck! |
|
| Back to top |
|
 |
Guest
|
Posted: Wed Jul 09, 2003 5:02 pm Post subject: |
|
|
| test |
|
| Back to top |
|
 |
ootheway Guest
|
Posted: Wed Jul 09, 2003 5:07 pm Post subject: impress -->pdf |
|
|
Hi, I try but got an IO exception...here is my function. Please help.
Thanks.
static public void saveDocument(XComponent doc, String name){
try {
//XTextDocument document = ... //This is where you get the XTextDocument
XComponent document = doc;
XModel xModel = (XModel)UnoRuntime.queryInterface(XModel.class, document);
XFrame xFrame = xModel.getCurrentController().getFrame();
xFrame.activate();
XStorable xStorable = (XStorable)UnoRuntime.queryInterface(XStorable.class, document);
PropertyValue[] props = new PropertyValue[2];
props[0] = new PropertyValue();
props[0].Name = "FilterName";
props[0].Value = "writer_pdf_Export";
props[1] = new PropertyValue();
props[1].Name = "CompressionMode";
props[1].Value = "1";
String tURL = "file:///D:/PDFTest.pdf";
xStorable.storeToURL(tURL, props);
System.out.println("document save!");
} catch (Exception ex) {
//Exception handling goes here
System.err.println( ex );
}
} |
|
| Back to top |
|
 |
ootheway Guest
|
Posted: Fri Jul 18, 2003 1:59 pm Post subject: |
|
|
props[0].Value = "writer_pdf_Export";
for impress to pdf, change this value to:
props[0].Value = "impress_pdf_Export"; |
|
| Back to top |
|
 |
AfinitySix General User

Joined: 05 Jul 2003 Posts: 9 Location: Malaysia
|
Posted: Sat Jul 19, 2003 8:53 am Post subject: Null XComponent and XModel |
|
|
I noticed the statement you used implicitly casts doc to an XComponent. Although all documents are based on the XComponent, you may need to use the UnoRuntime to query the interface to get a proper interface.
Try putting a statement after the code:
| Code: |
XModel xModel = (XModel)UnoRuntime.queryInterface(XModel.class, document);
if(xModel == null) {
System.out.println("Hey, this is XModel here, and I have been assigned a null value!");
System.exit(-1);
}
|
I suspect that the xModel you obtained could not have been parsed correctly. But that's just my two cents. I shall look into this further... |
|
| Back to top |
|
 |
Guest
|
Posted: Thu Oct 02, 2003 1:05 pm Post subject: Re: PDF Generation |
|
|
| AfinitySix wrote: | Generating PDF Documents via OpenOffice.org was never possible until the 1.1 Beta version.
I assume you have gone through the Developer's samples about Document Handling, and you are familar with the XInterface concepts.
I will no go through the details about obtaining an XTextDocument instance.
The codes used to generate PDF are as follows:
| Code: |
try {
XTextDocument document = ... //This is where you get the XTextDocument
XModel xModel = (XModel)UnoRuntime.queryInterface(XModel.class, document);
XFrame xFrame = xModel.getCurrentController().getFrame();
xFrame.activate();
XStorable xStorable = (XStorable)UnoRuntime.queryInterface(XStorable.class, document);
PropertyValue[] props = new PropertyValue[2];
props[0] = new PropertyValue();
props[0].Name = "FilterName";
props[0].Value = "writer_pdf_Export";
props[1] = new PropertyValue();
props[1].Name = "CompressionMode";
props[1].Value = "1";
String tURL = "file:///D:/GeneratedDocs/PDFTest.pdf";
xStorable.storeToURL(tURL, props);
} catch (Exception ex) {
//Exception handling goes here
}
|
This code snipet simply shows an example of storing an XTextDocument in PDF format, to a target URL specified by tURL. The main point to note is that you have to activate the XFrame in order to generate the PDF Document (refer to code).
The Property sets are simply used to tell the XStorable interface about how the XTextDocument is to be stored. In this case, we simply use the writer_pdf_Export filter to save the file as.
Good luck! |
|
|
| Back to top |
|
 |
didierkl Guest
|
Posted: Tue Oct 28, 2003 7:26 am Post subject: IOException |
|
|
Hi all, I've been trying for a while to use the filters, but I never managed to use them. I need to export an OpenOffice file to the pdf file format, for that I created a method based on the example from this topic. Here's my code:
private boolean convertToPDF(String filename)
{
// Converting the document to the favoured type
try {
String stringUrl = "file:///"+filename.replace('\\', '/' );
XComponentLoader CompLoader = connect2Office();
// Loading the wanted document
XComponent objectDocumentToStore =CompLoader.loadComponentFromURL(stringUrl, "_blank", 0, new PropertyValue[0] );
XModel xModel = (XModel)UnoRuntime.queryInterface(XModel.class, objectDocumentToStore);
XFrame xFrame = xModel.getCurrentController().getFrame();
xFrame.activate();
XStorable xstorable =( XStorable ) UnoRuntime.queryInterface( XStorable.class,objectDocumentToStore );
PropertyValue[] props = new PropertyValue[2];
props[0] = new PropertyValue();
props[0].Name = "FilterName";
props[0].Value = "writer_pdf_Export";
props[1] = new PropertyValue();
props[1].Name = "CompressionMode";
props[1].Value = "1";
stringUrl = "file:///e:/test.pdf";
xstorable.storeAsURL( stringUrl, props );
objectDocumentToStore.dispose();
}
catch( Exception exception )
{
exception.printStackTrace();
return false;
}
return true;
}
Is there something wrong?? When I execute this code I get the follwing exception:
com.sun.star.io.IOException:
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:274)
at com.sun.star.lib.uno.protocols.urp.Unmarshal.readThrowable(Unmarshal.java:315)
at com.sun.star.lib.uno.protocols.urp.Unmarshal.readAny(Unmarshal.java:157)
at com.sun.star.lib.uno.protocols.urp.Unmarshal.readObject(Unmarshal.java:404)
at com.sun.star.lib.uno.protocols.urp.urp.readReply(urp.java:192)
at com.sun.star.lib.uno.protocols.urp.urp.readMessage(urp.java:308)
at com.sun.star.lib.uno.protocols.urp.urp.readMessage(urp.java:607)
at com.sun.star.lib.uno.bridges.java_remote.java_remote_bridge$MessageDispatcher.invoke(java_remote_bridge.java:182)
at com.sun.star.lib.uno.bridges.java_remote.java_remote_bridge$MessageDispatcher.run(java_remote_bridge.java:173)
I need help!!!
Thanks,
Didier Klein |
|
| Back to top |
|
 |
DannyB Moderator


Joined: 02 Apr 2003 Posts: 3991 Location: Lawrence, Kansas, USA
|
|
| Back to top |
|
 |
didierkl Guest
|
Posted: Tue Oct 28, 2003 10:54 pm Post subject: Compression mode |
|
|
Hi,
I found the compression mode argument in various threads of this forum... I don't know if it works but the people who used seemed to be happy with it. Anyway, when I try to leave out the compression mode:
| Code: | XStorable xstorable =( XStorable ) UnoRuntime.queryInterface( XStorable.class,objectDocumentToStore );
PropertyValue[] props = new PropertyValue[1];
props[0] = new PropertyValue();
props[0].Name = "FilterName";
props[0].Value = "writer_pdf_Export";
stringUrl = "file:///e:/ooTEST.pdf";
xstorable.storeAsURL( stringUrl, props ); |
I get the same exception.
When I try with an unknown filter:
| Code: |
PropertyValue[] props = new PropertyValue[1];
props[0] = new PropertyValue();
props[0].Name = "FilterName";
props[0].Value = "what_the_hell_filter"; |
I still get the same exception ... does it come from a configuration problem... it seems that there's an invocation problem...
Here's the exception I get:
com.sun.star.io.IOException:
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:274)
at com.sun.star.lib.uno.protocols.urp.Unmarshal.readThrowable(Unmarshal.java:315)
at com.sun.star.lib.uno.protocols.urp.Unmarshal.readAny(Unmarshal.java:157)
at com.sun.star.lib.uno.protocols.urp.Unmarshal.readObject(Unmarshal.java:404)
at com.sun.star.lib.uno.protocols.urp.urp.readReply(urp.java:192)
at com.sun.star.lib.uno.protocols.urp.urp.readMessage(urp.java:308)
at com.sun.star.lib.uno.protocols.urp.urp.readMessage(urp.java:607)
at com.sun.star.lib.uno.bridges.java_remote.java_remote_bridge$MessageDispatcher.invoke(java_remote_bridge.java:182)
at com.sun.star.lib.uno.bridges.java_remote.java_remote_bridge$MessageDispatcher.run(java_remote_bridge.java:173)
If anyone knows how to solve this!! Please help me
Thanks,
Didier Klein |
|
| Back to top |
|
 |
didierkl Guest
|
Posted: Wed Oct 29, 2003 2:13 am Post subject: I think I solved the problem |
|
|
Hi all,
After trying a lot of different stuff, I tried to use the storeToURL instead of storeAsUrl... and guess what it worked !!
Anyway this seems to be working alright, but I still have a strange behaviour of openoffice while loading the sxw document. Sometimes OpenOffice crashes and sometimes it doesn't ... Anyone having the same problem ???
The compressionMode parameter doesn't work... I don't know if it's normal or not but when I'm specifying this parameter, I get the same exception as mentionned before (IOException).
See y'all,
Didier Klein  |
|
| Back to top |
|
 |
HeS Guest
|
Posted: Wed Oct 29, 2003 2:28 pm Post subject: Spreadsheet to PDF |
|
|
To save spreadsheet as PDF file.
1. FilterName="calc_pdf_Export" (NOT "writer_pdf_Export")
2. Use "storeToURL"
You need not activate XFrame. |
|
| Back to top |
|
 |
kwoot Guest
|
Posted: Wed Nov 05, 2003 10:13 am Post subject: exporting to pdf using external program |
|
|
since the pdf export function is unable to export eps graphs in the header I do a print to ps and then ps2pdf in the shell. It works at least.
Now I want to automate this:
-get the name of the document
-replace .sxw with .pdf
-start shell with ps2pdf documentname pdfname
can anyone tell me how to get the documentname?
example of shell syntax would be nice (if someone has it)
thanks |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|