使用java将DOC [HWPFDocument]转换为pdf [带字体和图像]

时间:2017-12-29 10:19:15

标签: java pdf apache-poi hwpf

将doc文件转换为pdf

我使用以下代码:

        POIFSFileSystem fs = null;
        Document Pdfdocument = new Document();

        fs = new POIFSFileSystem(new FileInputStream(srcFile));
        HWPFDocument doc = new HWPFDocument(fs);
        WordExtractor we = new WordExtractor(doc);

        PdfWriter writer = PdfWriter.getInstance(Pdfdocument, new 
        FileOutputStream(targetFile));

        Pdfdocument.open();
        writer.setPageEmpty(true);
        Pdfdocument.newPage();
        writer.setPageEmpty(true);
        String[] paragraphs = we.getParagraphText();
        for (int i = 0; i < paragraphs.length; i++) {
            Pdfdocument.add(new Paragraph(paragraphs[i]));
        }

这会生成没有格式和图像的pdf 偶数字体将丢失。

由于WordExtractor仅使用文字 有没有其他方式转换字体和图像。 转换形式 doc(HWPFDocument)但不是docx

我已经提到了这些SO链接

Convert doc to pdf using Apache POI

https://stackoverflow.com/a/6210694/6032482

how to convert doc,docx files to pdf in java programatically

还有更多,但发现了 他们都使用WordExtractor。

注意: 我不能使用图书馆办公室 也不 的Aspose

可以使用:

完成
  

ApachePOI

     

DOCX4j

     

iText的

0 个答案:

没有答案
相关问题