bas*_*aad 5 java javafx pdfbox javafx-8
我目前正在使用此代码将 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;
}
Run Code Online (Sandbox Code Playgroud)
然后,我在 JavaFX ImageView 中显示了转换后的图像。
此外,我需要导入这两个包,而我不使用它们:
import org.apache.commons.logging.LogFactory;
import org.apache.fontbox.afm.AFMParser;
Run Code Online (Sandbox Code Playgroud)
两个问题:
我想在 JavaFX 中快速显示 PDF,两到三秒太长了。非常欢迎在 JavaFX 中显示 PDF 的任何其他方式(除了将其转换为图像)。
任何帮助是极大的赞赏!
我在将 pdf 转换为图像时也遇到了类似的问题,我通过将 PDFBox 从 1.8 升级到 2.0 解决了这个问题。这使我的表现提高了 50%。以前我的应用程序需要大约 10 秒才能将 pdf 转换为图像,现在只需 5 秒。升级 PDFBox 时请使用以下链接作为参考 -
https://pdfbox.apache.org/2.0/migration.html
PDFBox 不需要额外导入。
问候,
尤格什
| 归档时间: |
|
| 查看次数: |
1828 次 |
| 最近记录: |