添加MS Office文档为PDF格式通过Apache PDFBox的 [英] Add MS Office Documents to PDF via Apache PDFBox

查看:264
本文介绍了添加MS Office文档为PDF格式通过Apache PDFBox的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Apache PDFBox的( http://pdfbox.apache.org/ )创建PDF出任意金额的文件,包括图片和其他PDF文件。现在我需要的MS Office文档(Word,Excel和Outlook中的MSG)添加到PDF。该文件可以有几乎所有Office版本,所以不授予该文件是一个新的Office文件(例如DOCX)或旧的(例如DOC)。

I'm using Apache PDFBox (http://pdfbox.apache.org/) for creating PDFs out of an arbitrary amount of files, including Images and other PDFs. Now I need to add MS Office Documents (Word, Excel and Outlook MSGs) to the PDF. The files can have nearly every Office Version, so it is not granted that the file is a new office file (e.g. docx) or an old one (e.g. doc).

有没有办法只能用免费工具来做到这一点?我最初的想法是阅读与Apache POI每个文件的contnet( http://poi.apache.org/ )和重建文件作为一个新的PDF页面,但这可能会变得非常昂贵,因为这PDF创建由超过五十人在服务器上使用。

Is there any way to do this only with free tools? My first idea is to read the contnet of every file with Apache POI (http://poi.apache.org/) and recreate the file as a new PDF page, but this can become very costly, as this PDF creation is used on a server by more than fifty people.

推荐答案

在服务器上安装开放式办公。它会转换成DOCX,DOC文件.PDF。

Install open office on you server. and it will convert "docx,doc" document to ".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();
    }

}

这篇关于添加MS Office文档为PDF格式通过Apache PDFBox的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆