2011-03-31 115 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();