6

Apache PDFBox ( http://pdfbox.apache.org/ ) を使用して、画像やその他の PDF を含む任意の量のファイルから PDF を作成しています。ここで、MS Office ドキュメント (Word、Excel、および Outlook MSG) を PDF に追加する必要があります。ファイルにはほぼすべての Office バージョンが含まれている可能性があるため、ファイルが新しい Office ファイル (docx など) であるか、古い Office ファイル (doc など) であるとは限りません。

無料のツールだけでこれを行う方法はありますか? 私の最初のアイデアは、すべてのファイルの内容を Apache POI ( http://poi.apache.org/ ) で読み取り、ファイルを新しい PDF ページとして再作成することですが、この PDF 作成が使用されているため、非常にコストがかかる可能性があります。 50人以上のサーバー。

4

1 に答える 1

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("sample.docx");

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

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

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

        con.disconnect();
    }

}
于 2013-05-17T09:11:38.390 に答える