gpt4 book ai didi

java - PDFBox:将 PDF 转换为图像比预期慢

转载 作者:行者123 更新时间:2023-12-02 03:46:36 32 4
gpt4 key购买 nike

我目前正在使用此代码将 pdf 转换为图像:

@SuppressWarnings("unchecked")
public static Image convertPDFtoImage(ByteArrayInputStream bais) {

Image convertedImage = null;

try {

PDDocument document = PDDocument.load(bais);
List<PDPage> list = document.getDocumentCatalog().getAllPages();
PDPage page = list.get(0);

BufferedImage image = page.convertToImage(BufferedImage.TYPE_INT_RGB, 64);
convertedImage = SwingFXUtils.toFXImage(image, null);

document.close();

}
catch (Exception e) {
e.printStackTrace();
}

return convertedImage;
}

然后,我在 JavaFX ImageView 中显示转换后的图像。

此外,我需要导入这两个包,但我没有使用它们:

import org.apache.commons.logging.LogFactory;
import org.apache.fontbox.afm.AFMParser;

两个问题:

  • 将简单的一页 PDF 转换为 DPI 设置为 64 的图像(在我看来并没有那么高)通常需要两到三秒吗?有点慢。
  • 为什么我需要这两个导入,而我不使用它们?如果我不导入它们,我会收到很多错误,并且转换将无法进行。

我想在 JavaFX 中快速显示 PDF,两到三秒太长了。在 JavaFX 中显示 PDF 的任何其他方式(除了将其转换为图像)都非常受欢迎。

非常感谢任何帮助!

最佳答案

  1. 我在将 pdf 转换为图像时也遇到了类似的问题,我通过将 PDFBox 从 1.8 升级到 2.0 解决了这个问题。这使我的表现提高了 50%。以前我的应用程序需要大约 10 秒才能将 pdf 转换为图像,现在只需 5 秒。升级 PDFBox 时请使用以下链接作为引用 -
    https://pdfbox.apache.org/2.0/migration.html

  2. PDFBox 不需要额外导入。

问候,
尤格什

关于java - PDFBox:将 PDF 转换为图像比预期慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26827367/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com