开发者

OpenOffice SDK: convert document to PDF

开发者 https://www.devze.com 2023-02-20 22:57 出处:网络
I\'m trying to build an application to convert documents (word, powerpoint) to PDF using the OpenOffice SDK.

I'm trying to build an application to convert documents (word, powerpoint) to PDF using the OpenOffice SDK.

I'm using C++ and all I want the application to do is take an input document filename and and output PDF filename, and do the conversion.

Are there any samples or easy way to get started? Most of the documentation I se开发者_运维知识库e is using Java.


You can get an example source code here:

http://forum.openoffice.org/en/forum/viewtopic.php?t=3801


I do this with C#, I share with you hoping it helps:

// Connect to a running office and get the service manager
unoidl.com.sun.star.uno.XComponentContext m_xContext = uno.util.Bootstrap.bootstrap();
var mxMSFactory = (XMultiServiceFactory)m_xContext.getServiceManager();
XComponentLoader desktop = (XComponentLoader)mxMSFactory.createInstance("com.sun.star.frame.Desktop");
XComponentLoader xComponentLoader = (unoidl.com.sun.star.frame.XComponentLoader)desktop;
PropertyValue[] properties = new PropertyValue[1];
properties[0] = new PropertyValue();
properties[0].Name = "Hidden";
properties[0].Value = new uno.Any(true);

XComponent xComponent = xComponentLoader.loadComponentFromURL("file:///YOUR .ODT PATH", "_blank", 0, properties);
XTextDocument xDocument = (XTextDocument)xComponent;

XStorable xStorable = (XStorable)xDocument;
PropertyValue[] storeProps = new PropertyValue[3];
storeProps[0] = new PropertyValue();
storeProps[0].Name = "FilterName";
storeProps[0].Value = new uno.Any("writer_pdf_Export");
storeProps[1] = new PropertyValue();
storeProps[1].Name = "Overwrite";
storeProps[1].Value = new uno.Any(true);
storeProps[2] = new PropertyValue();
storeProps[2].Name = "SelectPdfVersion";
storeProps[2].Value = new uno.Any(1);

xStorable.storeToURL("file:///YOUR PDF PATH", storeProps);
xDocument.dispose();


The right way to start is reading the Developer's Guide.

Good stuff in our business ain't easy.

0

精彩评论

暂无评论...
验证码 换一张
取 消