2013-05-17 41 views
6

我使用Apache PDFBox(http://pdfbox.apache.org/)從任意數量的文件(包括圖像和其他PDF)創建PDF。現在我需要將MS Office文檔(Word,Excel和Outlook MSG)添加到PDF中。該文件可以有幾乎所有的Office版本,所以不授予該文件是一個新的Office文件(例如DOCX)或舊的(例如DOC)。通過Apache PDFBox將MS Office文檔添加到PDF

有沒有辦法只能用免費工具來做到這一點?我的第一個想法是閱讀與Apache POI(http://poi.apache.org/)每個文件的contnet並重新創建該文件作爲一個新的PDF頁面,但是這可能會變得非常昂貴,因爲這PDF創建由超過五十人的服務器上使用。

回答

4

你的服務器上安裝開放式辦公。它會將「docx,doc」文檔轉換爲「.pdf」。

package naveed.workingfiles; 

import java.io.*; 
import com.artofsolving.jodconverter.openoffice.connection.*; 
import com.artofsolving.jodconverter.openoffice.converter.*; 
import com.artofsolving.jodconverter.*; 

public class DocToPdf { 

    public static void main(String[] args) throws Exception { 

     //Creating the instance of OpenOfficeConnection and 
     //passing the port number to SocketOpenOfficeConnection constructor 
     OpenOfficeConnection con = new SocketOpenOfficeConnection(8100); 

     //making the connection with openoffice server 
     con.connect(); 

     // making the object of doc file and pdf file 
     File inFile = new File("Naveed.docx"); 

     //this is the final converted pdf file 
     File outFile = new File("NaveedPdf.pdf"); 

     //making the instance 
     DocumentConverter converter = new OpenOfficeDocumentConverter(con); 

     //passing both files objects 
     converter.convert(inFile, outFile); 

     con.disconnect(); 
    } 

} 
+0

謝謝,但我不允許地方安裝的東西,這是不是一種選擇;) – Mirco

+0

但沒有tooo多google搜索this..i得到這個solution.it作品 –