2011-03-31 81 views
0

我试图构建一个应用程序,使用OpenOffice SDK将文档(word,powerpoint)转换为PDF。OpenOffice SDK:将文档转换为PDF

我正在使用C++,并且我希望应用程序执行的操作是输入文档文件名并输出PDF文件名,然后执行转换。

有没有任何样品或简单的上手方法?我看到的大多数文档都是使用Java。

+0

我在同样的情况是,理想情况下,我需要开发一个C++应用程序将xls转换为pdf。到目前为止,我已经使用OO 3.3在C#中工作。我也发现了一些C++示例,但它们引用了OO头文件,这些头文件不是沿着OO的标准安装或OO SDK提供的。对此赞赏的任何指针! – fduff 2012-01-11 07:55:26

回答

0

我这样做是用C#,我与你希望它有助于分享:

// 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();