目录
no lcmm in java.library.path错误
原问题解决方法:https://github.com/opensagres/xdocreport/issues/161
POM依赖
<properties>
<java.version>1.8</java.version>
<poi.version>3.14</poi.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>${poi.version}</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>${poi.version}</version>
</dependency>
<dependency>
<groupId>fr.opensagres.xdocreport</groupId>
<artifactId>fr.opensagres.poi.xwpf.converter.pdf-gae</artifactId>
<version>2.0.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>fr.opensagres.xdocreport</groupId>
<artifactId>fr.opensagres.xdocreport.document</artifactId>
<version>2.0.1</version>
<scope>compile</scope>
</dependency>
</dependencies>
请记住,word转换如果没问题,那么就要设置pdf的字体,这个是铁律!
核心配置代码
将PdfOptions提出来作为方法使用
private PdfOptions getPdfOptions() {
PdfOptions pdfOptions = PdfOptions.create();
// 解决中文不显示问题
pdfOptions.fontProvider(new IFontProvider() {
@Override
public Font getFont(String familyName, String encoding, float size, int style, Color color) {
try {
File file = new File(pdfChineseTTF);
Preconditions.checkState(file.exists(), "中文字体文件不存在:" + pdfChineseTTF);
BaseFont bfChinese = BaseFont.createFont(pdfChineseTTF, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
Font fontChinese = new Font(bfChinese, size, style, color);
if (familyName != null) {
fontChinese.setFamily(familyName);
}
return fontChinese;
} catch (Throwable e) {
e.printStackTrace();
// An error occurs, use the default font provider.
return ITextFontRegistry.getRegistry().getFont(familyName, encoding, size, style, color);
}
}
});
return pdfOptions;
}
PDF下载流问题
注意前端PDF文件流空白问题参考以下方案进行处理
js下载PDF文件流,打开空白问题_使用jspdf导出服务器上pdf文件的时候文件里面没有内容_夏小锋的博客-CSDN博客
前端下载二进制流pdf文件,下载成功,打开空白问题解决_前端下载pdf文件流打开空白_Helen_fight的博客-CSDN博客
WPS模板问题
使用wps处理的template.docx文件不能识别到页脚信息,请使用微软提供的office进行编辑
以下是WPS footer xml部分,不是OOXML需要的解析范式:
<pkg:part pkg:name="/word/footer1.xml" pkg:contentType="application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml">
<pkg:xmlData>
<w:ftr xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape" xmlns:wpsCustomData="http://www.wps.cn/officeDocument/2013/wpsCustomData" mc:Ignorable="w14 w15 wp14">
<w:p>
<w:pPr>
<w:pStyle w:val="2"/>
<w:tabs>
<w:tab w:val="right" w:pos="8426"/>
</w:tabs>
<w:jc w:val="right"/>
<w:rPr>
<w:rFonts w:hint="default" w:eastAsia="宋体"/>
<w:lang w:val="en-US" w:eastAsia="zh-CN"/>
</w:rPr>
</w:pPr>
<w:r>
<w:rPr>
<w:sz w:val="18"/>
</w:rPr>
<mc:AlternateContent>
<mc:Choice Requires="wps">
<w:drawing>
<wp:anchor distT="0" distB="0" distL="114300" distR="114300" simplePos="0" relativeHeight="251659264" behindDoc="0" locked="0" layoutInCell="1" allowOverlap="1">
<wp:simplePos x="0" y="0"/>
<wp:positionH relativeFrom="margin">
<wp:align>center</wp:align>
</wp:positionH>
<wp:positionV relativeFrom="paragraph">
<wp:posOffset>0</wp:posOffset>
</wp:positionV>
<wp:extent cx="1828800" cy="1828800"/>
<wp:effectExtent l="0" t="0" r="0" b="0"/>
<wp:wrapNone/>
<wp:docPr id="3" name="文本框 3"/>
<wp:cNvGraphicFramePr/>
<a:graphic xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
<a:graphicData uri="http://schemas.microsoft.com/office/word/2010/wordprocessingShape">
<wps:wsp>
<wps:cNvSpPr txBox="1"/>
<wps:spPr>
<a:xfrm>
<a:off x="0" y="0"/>
<a:ext cx="1828800" cy="1828800"/>
</a:xfrm>
<a:prstGeom prst="rect">
<a:avLst/>
</a:prstGeom>
<a:noFill/>
<a:ln w="6350">
<a:noFill/>
</a:ln>
</wps:spPr>
<wps:style>
<a:lnRef idx="0">
<a:schemeClr val="accent1"/>
</a:lnRef>
<a:fillRef idx="0">
<a:schemeClr val="accent1"/>
</a:fillRef>
<a:effectRef idx="0">
<a:schemeClr val="accent1"/>
</a:effectRef>
<a:fontRef idx="minor">
<a:schemeClr val="dk1"/>
</a:fontRef>
</wps:style>
<wps:txbx>
<w:txbxContent>
<w:p>
<w:pPr>