小编Pra*_*tel的帖子

docx4j:docx 到 pdf 转换 - docx 内容未逐页显示为 pdf

问题:使用 DOCX4J 将 docx 转换为 pdf。问题是 docx 的内容没有逐页转换为 pdf 文档。pdf 第 1 页中出现了第 2 页的几行内容。

pom.xml:

<dependency>
    <groupId>org.docx4j</groupId>
    <artifactId>docx4j</artifactId>
    <version>6.1.2</version>
</dependency>
<dependency>
    <groupId>org.docx4j</groupId>
    <artifactId>docx4j-export-fo</artifactId>
    <version>6.1.0</version>
</dependency>
<dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>2.1</version>
</dependency>
<dependency>
    <groupId>com.itextpdf</groupId>
    <artifactId>itextpdf</artifactId>
    <version>5.4.3</version>
</dependency>

Run Code Online (Sandbox Code Playgroud)

代码:

private static void convertToPDFDocx4j() throws Exception {

    InputStream is = new FileInputStream(new File(inputfilepath));
    WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage
            .load(is);
    List sections = wordMLPackage.getDocumentModel().getSections();
    for (int i = 0; i < sections.size(); i++) {
        wordMLPackage.getDocumentModel().getSections().get(i)
                .getPageDimensions();
    }
    Mapper fontMapper = new IdentityPlusMapper();
    PhysicalFont font = …
Run Code Online (Sandbox Code Playgroud)

java pdf docx docx4j

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

docx ×1

docx4j ×1

java ×1

pdf ×1