使用xdocreport将docx转换为pdf时生成的空pdf

时间:2017-01-10 10:36:42

标签: apache apache-poi xdocreport

当我使用下面的代码将docx文件转换为pdf时,会生成一个空的pdf文件。任何人都可以帮我纠正这个问题。

Docx File
PDF File

  import java.io.File;
  import java.io.FileInputStream;
  import java.io.FileOutputStream;
  import java.io.InputStream;
  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;
  public class ConversionDocxToPDF {

public static void main(String[] args) {

    try {


        InputStream is = new FileInputStream(new File("C:\\MtgMin.docx"));
       XWPFDocument document = new XWPFDocument(is);        

        PdfOptions options = PdfOptions.create(); 

        OutputStream out = new FileOutputStream(new File("C:\\MtgMin.pdf"));
        PdfConverter.getInstance().convert(document, out, options);


    } catch (Throwable e) {
        e.printStackTrace();
    }
 }

}

0 个答案:

没有答案