2

I need to be able to generate a png thumbnail of a specific page of a PDF document in OS X.

I can use 'qlmanage -p MyFile.pdf -o outputDir -s1000' to get a 1000-pixel wide PNG of the first page. This works perfectly, and is almost exactly what I need. The only missing piece is being able to specify a certain page number of the PDF.

Can this be done with qlmanage, or some other command-line utility?

2 Answers 2

3

ImageMagick ought to be able to help:

convert -resize 10000x10000 MyFile.pdf[2] MyOutput.png

Where 2 is the page number. Enjoy!

5
  • ImageMagick seems broken. I downloaded the pre-built binary for OS X, but I can't get convert to work at all. This command: "convert -resize 1000x1000 DroboGuide.pdf MyOutput.png" gives me this error: "Postscript delegate failed `DroboGuide.pdf': No such file or directory @ error/pdf.c/ReadPDFImage/645.". The file does exist in the current working directory. Jan 28, 2011 at 13:04
  • 1
    It turns out that the reason ImageMagick was failing is that I need GhostScript installed in order to use ImageMagick with PDFs. I can't use GhostScript because it's GPL, and furthermore I ran into numerous problems trying to install it just to try it out. Even if we wanted to buy the non-GPL commercial license, the ImageMagick / GhostScript combo adds too much size, complexity, and new support requirements to bundle with our software. Thank you for the suggestion though! Jan 28, 2011 at 13:27
  • Well, in that case, you’ll probably need to create your own tool to do the same. OS X has built-in support for PDFs, so I’m sure there’s a way to render a specific page into an image. Check out CGPDFDocument and friends:developer.apple.com/library/mac/#documentation/GraphicsImaging/… Jan 28, 2011 at 22:36
  • That's how I was doing it before. The problem is that there is a memory leak in the PDF generation in Core Image (confirmed by Apple as radar #8668407), so I was going to try to switch to a command line that ran as its own process, instead of rendering the PDF thumbnail from in my process (which eventually runs out of memory). Jan 29, 2011 at 22:02
  • 1
    You could split your own PDF thumbnail-generating code into a separate process, then include it as a command-line utility with your application. Jan 29, 2011 at 23:12
0

You can use Aspose.Pdf to generate a thumbnail (or image) of any page. Very reliable and generates a perfect image (as good as Acrobat). Only downside is it takes ~20 SECONDS to generate a single thumbnail. And that sucks. Code is as follows:

    Document document = new Document(pdfPath);
    Page page = document.Pages[pageNum];
    document.RemoveMetadata();
    page.Flatten();
    page.SendTo(new PngDevice(page.PageInfo.Width, page.PageInfo.Height), pngPath);
    document.Dispose();

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.