我在java中使用openoffice API创建了一个文档。现在我想在我的机器上将该文档保存为pdf。 怎么做?
创建文档的代码是
// Create a document
XComponent xdocument = xCLoader.loadComponentFromURL("private:factory/swriter", "_blank", 0, new PropertyValue[0]);
// Get the textdocument
XTextDocument aTextDocument = ( XTextDocument )UnoRuntime.queryInterface(com.sun.star.text.XTextDocument.class, xdocument);
// Get its text
XText xText = aTextDocument.getText();
XTextRange xTextRange = xText.createTextCursor();
((XTextCursor)xTextRange).gotoEnd(true);
现在我要保存该文档。但我无法这样做。你能帮帮我吗?
我用于保存的代码是
//close the document
XCloseable xcloseable = (XCloseable) UnoRuntime.queryInterface(XCloseable.class, xdocument);
xcloseable.close(false);
// the url where the document is to be saved
String storeUrl = "D:\\OOo_doc.pdf";
// Save the document
XStorable xStorable = ( XStorable )UnoRuntime.queryInterface(XStorable.class, xdocument);
PropertyValue[] storeProps = new PropertyValue[0];
storeProps = new PropertyValue[1];
storeProps[0] = new PropertyValue();
storeProps[0].Name = "FilterName";
storeProps[0].Value = "writer_pdf_Export";
xStorable.storeToURL(storeUrl, storeProps);
这是我得到的例外
Exception in thread "main" com.sun.star.task.ErrorCodeIOException:
at com.sun.star.lib.uno.environments.remote.Job.remoteUnoRequestRaisedException(Job.java:182)
at com.sun.star.lib.uno.environments.remote.Job.execute(Job.java:148)
at com.sun.star.lib.uno.environments.remote.JobQueue.enter(JobQueue.java:344)
at com.sun.star.lib.uno.environments.remote.JobQueue.enter(JobQueue.java:313)
at com.sun.star.lib.uno.environments.remote.JavaThreadPool.enter(JavaThreadPool.java:101)
at com.sun.star.lib.uno.bridges.java_remote.java_remote_bridge.sendRequest(java_remote_bridge.java:652)
at com.sun.star.lib.uno.bridges.java_remote.ProxyFactory$Handler.request(ProxyFactory.java:154)
at com.sun.star.lib.uno.bridges.java_remote.ProxyFactory$Handler.invoke(ProxyFactory.java:136)
at com.sun.proxy.$Proxy10.storeToURL(Unknown Source)
at test.oo.main(oo.java:83)
但我不是要把它保存在所需的位置。请帮忙
答案 0 :(得分:0)
您可以尝试几种方法来诊断问题的原因: