美文网首页
使用itextpdf将html转pdf在linux下出现乱码

使用itextpdf将html转pdf在linux下出现乱码

作者: zornil | 来源:发表于2020-11-18 01:19 被阅读0次

使用itextpdf将html转成pdf在本机电脑上没有问题,部署在linux上出现乱码

1、版本
<dependency>
    <groupId>com.itextpdf</groupId>
    <artifactId>html2pdf</artifactId>
    <version>3.0.2</version>
</dependency>
2、解决方式

在项目下建立fonts文件夹,里面放入要使用的字体,如:经典宋体简.ttf 密码: j14q

        String fontsPath = "fonts/";
        ConverterProperties properties = new ConverterProperties();
        FontProvider fp = new FontProvider(); // 提供解析用的字体
        fp.addStandardPdfFonts(); // 添加标准字体库、无中文
        fp.addDirectory(fontsPath); // 自定义字体路径、解决中文,可先用绝对路径测试。
        properties.setFontProvider(fp);

生成的文档能够统一使用一个字体

相关文章

网友评论

      本文标题:使用itextpdf将html转pdf在linux下出现乱码

      本文链接:https://www.haomeiwen.com/subject/jprqiktx.html