使用 PDFBox 1.8.9 文本重叠的 PDF 到图像

标签 pdf pdf-generation pdfbox

我正在尝试使用 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:

enter image description here

使用上述代码转换的图像:

enter image description here

使用命令行转换图像:

enter image description here

最佳答案

当在服务器上找不到 Helvetica 和 Times New Roman 等字体时,PDFBox 会替换该字体。在我的Linux机器上安装上述字体后,问题就解决了。

关于使用 PDFBox 1.8.9 文本重叠的 PDF 到图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30725009/

相关文章:

CSS悬停菜单出现在pdf iframe后面

php - 在 FPDF 中显示值

css - ABCPdf 没有嵌入新添加的自定义字体

java - "(someString) Tj"到 java 字符串编码问题 (PDFBox)

java - 使用java itext或pdfbox在现有pdf中添加便笺

php - 在 PHP 中使用带有弯曲文本的 SVG 创建 PDF - 不显示任何文本

pdf - UICollectionView 在滚动后显示错误的单元格 - 出队问题?

java - PDF 框。使用相同图像生成多页文档

pdf - 带标签的 PDF 文件可以有演示文稿表格吗?

php - TCPDF - DIV 前后显示额外空间