将docx文件转换为pdf

时间:2016-07-20 11:29:14

标签: java pdf docx

我想使用apache.poi.xwpf将word文档(docx)转换为pdf格式。它转换为fine.But封面和图表不转换。我提到我的代码如下。我想知道什么是jar和如何将docx转换为pdf。所以请善意解决我的问题。

package javaapplication1;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import org.apache.poi.xwpf.converter.pdf.PdfConverter;
import org.apache.poi.xwpf.converter.pdf.PdfOptions;
import org.apache.poi.xwpf.usermodel.XWPFDocument;



/**
 *
 * @author Manos_T
 */
public class JavaApplication1 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws FileNotFoundException, IOException {
        String filePath = "C:/Users/manos_t/Desktop/777.docx";
        FileInputStream fInputStream = new FileInputStream(new File(filePath));
//        XWPFDocument document = new XWPFDocument(Data.class.getResourceAsStream(filePath));
        XWPFDocument document = new XWPFDocument(fInputStream);

        File outFile = new File("C:/Users/manos_t/Desktop/777.pdf");
        outFile.getParentFile().mkdirs();

        OutputStream out = new FileOutputStream(outFile);
        PdfOptions options = PdfOptions.create().fontEncoding("windows-1250");
        PdfConverter.getInstance().convert(document, out, options);

        System.out.println("Sucess");

    }
}

0 个答案:

没有答案