【发布时间】:2015-09-04 12:40:48
【问题描述】:
我正在使用 Ghost4J 库 (http://ghost4j.sourceforge.net) 将幻灯片的 PDF 文件拆分为多个图像。我遇到的问题是我得到的图像是幻灯片在角落里而且非常小。我希望我的图像从 PDF 中获取页面的格式,但我不知道该怎么做。这是我正在使用的代码。
PDFDocument examplePDF = new PDFDocument();
String filePath="input.pdf";
File file=new File(filePath);
examplePDF.load(file);
List<org.ghost4j.document.Document> docs=examplePDF.explode();
SimpleRenderer renderer = new SimpleRenderer();
renderer.setResolution(300);
int counter=0;
for ( org.ghost4j.document.Document d : docs){
List<Image> img=renderer.render(d);
ImageIO.write((RenderedImage) img.get(0), "png", new File(
(counter+ 1) + ".png"));
counter++;
}
我认为问题在于没有考虑到我的原始 pdf 没有标准 pdf 页面大小的 explode 方法。
PD。我首先尝试了this question 的第二个答案中的代码,但是当文档有很多页面时,这给了我一个堆空间错误。
【问题讨论】: