我正在使用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页面大小。
PD。我首先尝试了this question的第二个答案中的代码,但是当文档有很多页面时,这给了我一个堆空间错误。
答案 0 :(得分:0)
您会考虑使用ImageMagick吗?
convert -density 300 input.pdf output.png
会给你output-1.png,output-2.png等等。