0

I'm using Ghost4J library (http://ghost4j.sourceforge.net) to split a PDF file of slides into several images. The problem I have is that I get images where the slides are in the corner and very small. I want my images to get the format of the page from the PDF, but I don't know how to do it. Here is the code I'm using.

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++;
        }

I think the problem is in the explode method that doesn't take into account that my original pdf didn't have standard pdf page size.

PD. I first tried the code from the second answer of this question but that gave me a heap space error when the document have a lot of pages.

Community
  • 1
  • 1
Ignacio
  • 386
  • 4
  • 19

1 Answers1

0

Would you consider using ImageMagick instead?

convert -density 300 input.pdf output.png

would give you output-1.png, output-2.png, etc.

erjiang
  • 44,417
  • 10
  • 64
  • 100