我正在寻找一个 Java 库,它可以获取 PDF 并从第一页创建缩略图 (PNG)。
我已经看过 JPedal,但其疯狂的许可费完全令人望而却步。我目前正在使用 iText 来操作 PDF 文件,但我相信它不会生成缩略图。我可以在命令行上使用 Ghostscript 之类的东西,但我希望如果可能的话,让我的项目全部使用 Java。
PDF渲染器 https://github.com/katjas/PDFrenderer是一个 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
);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)