我正在寻找,将可以采取一个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您支付的活跃和发展图书馆不是一个死的项目。