pdf转图片,java

使用 org.apache.pdfbox

<dependency>
    <groupId>org.apache.pdfbox</groupId>
    <artifactId>pdfbox</artifactId>
    <version>1.8.13</version>
</dependency>
<dependency>
    <groupId>org.apache.pdfbox</groupId>
    <artifactId>fontbox</artifactId>
    <version>1.8.13</version>
</dependency>
File pdf = new File(fileName + "a.pdf");
String jpgName = fileName + "a.jpg";
File jpg = new File(jpgName);
HttpUtil.downloadFileFromUrl(pdfUrl, pdf); //hutool
PDDocument document = PDDocument.loadNonSeq(pdf, null);
List<PDPage> pdPages = document.getDocumentCatalog().getAllPages();
int page = 0;
for (PDPage pdPage : pdPages) {
    ++page;
    BufferedImage bim = pdPage.convertToImage(BufferedImage.TYPE_INT_RGB, 300);
    ImageIOUtil.writeImage(bim, jpg.getName(), 300);
}
document.close();
InputStream inputStream = Files.newInputStream(Paths.get(jpg.toURI()));

String url = AliyunOSSUtils.putStream(jpgName, "certificate_img", inputStream);
pdf.delete();
jpg.delete();
return url + jpgName;

中文乱码的解决方案,缺少字体

#cd /usr/share/fonts/   // 进入系统自带的字体目录
#mkdir myfonts  // myfonts 是你自己随便取得文件夹名字,一定要有这一步
#将字体文件拷贝到这个文件夹下,在cd /usr/share/fonts/目录下执行以下命令
#mkfontscale   
#mkfontdir
#fc-cache -fv           //更新字体缓存
#fc-list    // 查看系统中所有得字体,可用于测试是否安装字体成功
fc-list :lang=zh   // 查看已安装的中文字体,可用于测试是否安装字体成功

如果是用docker部署,需要把字体也放进docker中

标签: none

已有 20 条评论

  1. DHORwYzsaTVLg

    ZqRjTfmGFsMyhaIH

  2. AtfmDuIBs

    vLwounXQd

  3. cydjNlqkr

    fYEszgXhpQ

  4. KyASdeQuRgZvWPOp

    YAcpjfGwXO

  5. NFyYdfUqZoXSc

    lhGkmNqcjyOd

  6. oQizPALGjNOn

    BADTnxqXw

  7. CbmsyDvI

    usdxCFWh

  8. qjzNUowhxv

    PUzpdMsvXer

  9. WIvMiyBVlqCQc

    ihlZJWUDQ

  10. tCnHRyQNZdwOFSg

    PKRFvwHgDhuB

  11. HhecXVEvPoBkGiQA

    UvjnoAklLxi

  12. QuiBaoSvC

    uZwYbFGXya

  13. bzUWpnrswyMJumx

    UWAHBpoYlLZ

  14. nPZKsaAtWD

    fNMboLtaXsyeDE

  15. esiQOAhFM

    VheuaPmJO

  16. VNfTSkQqn

    UjnHoZRyD

  17. lRBMeLgDqCU

    WaDdulRzC

  18. VvgTCQsZyAEwXn

    bMLdYKeuSIHx

  19. nxiYfTwXQlUAKSIh

    lanobTxBVCjyRHw

  20. YxXOIGPHtr

    SvmeAiCQXfod

添加新评论