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.

1 Answer 1

0

Would you consider using ImageMagick instead?

convert -density 300 input.pdf output.png

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

1
  • I have to integrate the code into a java project, so that doesn't work for me.
    – Ignacio
    Jun 18, 2015 at 18:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.