我正在尝试使用PDFBox 1.8.9将PDF转换为图像。字体重叠。我知道在PDFBox 2.0 SNAPSHOT中不会出现此问题。但在官方公布之前,它不能用于生产。
以下是代码:
PDDocument pdDocument = PDDocument.load(new File("test.pdf"));
List<PDPage> pages = pdDocument.getDocumentCatalog().getAllPages();
int pageCounter = 1;
for (PDPage page : pages) {
BufferedImage bufferedImage = page.convertToImage();
File imageFile = new File(String.format("/tmp/pdf-image-%s.jpg", pageCounter));
ImageIO.write(bufferedImage, "jpg", imageFile);
pageCounter++;
}
除了重叠之外,字体看起来与PDF类似吗?
当我尝试通过命令行使用pdfbox-app-1.8.9.jar将PDF转换为图像时,将使用不同的字体生成图像。 PDFBox有任何选项可以使用.ttf指定自定义字体吗?在这种情况下,我该如何指定?
实际PDF:
使用上面的代码转换图像:
使用命令行转换图像:
答案 0 :(得分:3)
当在服务器上找不到时,PDFBox会替换Helvetica和Times New Roman等字体。在我的Linux机器上安装上述字体后,问题就解决了。