在Java中为PDF创建缩略图图像

我正在寻找一个可以从第一页获取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 ); 

只要您只使用他们使用的PDF文件子集,PDF渲染器就可以了。 使用JPod和JPedal,您需要为活跃和开发的库付费而不是死项目。