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();
        }
    }


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM