POI XWPFDocument 转 PDF
注意: 使用模板编辑,导出, 如果手动new的XWPFDocument 总是有问题
public static void main(String[] args) {
try {
// 1) Load DOCX into XWPFDocument
XWPFDocument document = new XWPFDocument(new FileInputStream(OUTPUT_DESKTOP_PATH + "123.docx"));
document.createStyles();
XWPFParagraph paragraph = document.createParagraph();
XWPFRun run = paragraph.createRun();
run.setText("123213");
// 2) Prepare Pdf options
PdfOptions options = PdfOptions.create();
// 3) Convert XWPFDocument to Pdf
OutputStream out = new FileOutputStream(new File(OUTPUT_DESKTOP_PATH + "HelloWord.pdf"));
PdfConverter.getInstance().convert(document, out, options);
} catch (IOException e) {
e.printStackTrace();
}
}