问题:使用DOCX4J将docx转换为pdf时,出现问题,即docx的内容未逐页转换为pdf文档。第2页的几行出现在pdf的第1页中。
pom.xml:
想知道docx4j是否有控制它的设置?
DOCX: PDF: 尝试了一下,但没有什么帮助: 用Java将docx文件转换为PDF
<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>
代码:
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 = PhysicalFonts.getPhysicalFonts().get(
"Comic Sans MS");//set your desired font
fontMapper.getFontMappings().put("Algerian", font);
wordMLPackage.setFontMapper(fontMapper);
PdfSettings pdfSettings = new PdfSettings();
org.docx4j.convert.out.pdf.PdfConversion conversion = new org.docx4j.convert.out.pdf.viaXSLFO.Conversion(
wordMLPackage);
OutputStream out = new FileOutputStream(new File(outputfilepath));
conversion.output(out, pdfSettings);
System.out.println("DONE!!");
}
想知道docx4j是否有控制它的设置?
DOCX: PDF: 尝试了一下,但没有什么帮助: 用Java将docx文件转换为PDF