2013-05-17 1 views
6

이미지 및 기타 PDF를 포함한 임의의 양의 파일을 PDF로 생성하기 위해 Apache PDFBox (http://pdfbox.apache.org/)를 사용하고 있습니다. 이제 MS Office 문서 (Word, Excel 및 Outlook MSG)를 PDF에 추가해야합니다. 파일에는 거의 모든 Office 버전이있을 수 있으므로 해당 파일이 새로운 오피스 파일 (예 : docx) 또는 이전 오피스 파일 (예 : doc)인지는 알 수 없습니다.Apache를 통해 MS 오피스 문서를 PDFBox에 추가하십시오. PDFBox

무료 도구에서만이 작업을 수행 할 수있는 방법이 있습니까? 첫 번째 아이디어는 Apache POI (http://poi.apache.org/)로 모든 파일의 콘넷을 읽고 새 PDF 페이지로 파일을 다시 작성하는 것입니다.하지만이 PDF 작성은 50 명이 넘는 서버에서 사용되므로 비용이 많이 소요될 수 있습니다.

답변

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

하지만 요오 ... 많은 this..i에 대한 인터넷 검색을 않은이 solution.it의 작품을 가지고 –

관련 문제