opensagres / xdocreport

XDocReport means XML Document reporting. It's Java API to merge XML document created with MS Office (docx) or OpenOffice (odt), LibreOffice (odt) with a Java model to generate report and convert it if you need to another format (PDF, XHTML...).

Home Page:https://github.com/opensagres/xdocreport

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

When word converts pdf, it cannot convert lines.

LoveSeriously opened this issue · comments

When word converts pdf, it cannot convert lines.

word:

image

pdf:
image

pom.xml

        <dependency>
            <groupId>fr.opensagres.xdocreport</groupId>
            <artifactId>fr.opensagres.poi.xwpf.converter.pdf</artifactId>
            <version>2.0.4</version>
        </dependency>
        <dependency>

java:

        public void wordToPdf(MultipartFile file, OutputStream outputStream) {
            // 转换
            try {
                // 使用WORD文档构建XWPFDocument对象
                XWPFDocument document = new XWPFDocument(file.getInputStream());
                // options
                PdfOptions options = PdfOptions.create();
                String pdfTmpName = "/tmp/tmp.pdf";
                PdfConverter.getInstance().convert(document, new FileOutputStream(pdfTmpName), options);
                FileInputStream inputStream = new FileInputStream(pdfTmpName);

                IOUtils.copy(inputStream, outputStream);
            } catch (OLE2NotOfficeXmlFileException ex) {
                throw new RuntimeException("暂时不支持word2003版本!");
            } catch (IOException e) {
                e.printStackTrace();
            }
        }