java - 在 Java 中为 PDF 创建缩略图

标签 java pdf thumbnails image-generation

我正在寻找可以获取 PDF 并从第一页创建缩略​​图 (PNG) 的 Java 库。

我已经看过 JPedal,但其疯狂的许可费用令人望而却步。我目前正在使用 iText 来处理 PDF 文件,但我相信它不会生成缩略图。我可以在命令行上使用 Ghostscript 之类的东西,但我希望尽可能让我的项目全部使用 Java。

最佳答案

PDF Renderer是一个 LGPL 许可的纯 java 库,它使这变得像(取自他们的示例页面)一样简单:

File file = new File("test.pdf");
RandomAccessFile raf = new RandomAccessFile(file, "r");
FileChannel channel = raf.getChannel();
ByteBuffer buf = channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size());
PDFFile pdffile = new PDFFile(buf);

// draw the first page to an image
PDFPage page = pdffile.getPage(0);

//get the width and height for the doc at the default zoom 
Rectangle rect = new Rectangle(0,0,
                (int)page.getBBox().getWidth(),
                (int)page.getBBox().getHeight());

//generate the image
Image img = page.getImage(
                rect.width, rect.height, //width & height
                rect, // clip rect
                null, // null for the ImageObserver
                true, // fill background with white
                true  // block until drawing is done
                );

关于java - 在 Java 中为 PDF 创建缩略图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2844961/

相关文章:

node.js - Node : generating thumbnail image from video buffer (not file path)

iOS 13 缩略图扩展 (QLThumbnailProvider) 未被调用

pdf - 如何在 TCPDF 中实现自定义字体

银光 PDF 查看器

java - 返回值: boolean vs int flag vs exception

java - lambda 表达式中的错误返回类型 : Predicate<T> cannot be converted to Criteria<T>

html - 如何在 reStructuredText 中创建 PDF?

Android Eclipse 查询库外图片的缩略图

java - OWLAPI : Get the IRI in a AnnotationAssertion

java - 如何在属性中将字体安装到 NetBeans?