Make a screenshot every page of PDF file
ghostscript, pdf, php
Solution
Maybe the "make a screenshot" can be replaced for your purpose by "create a raster image" for each PDF page?
In this case you could use ImageMagick and/or one of its PHP-enabled libraries. Here is a command line representation:
convert some.pdf[15-19] some.png
This will convert not all pages, but the page range 16--20 (page counting here is zero-based (not intuitive, I know...). To convert all pages, just skip the `[15-19]` part.
The output PNG names will be `some-0.png`, `some-1.png`, ... `some-4.png`.
To create JPEG or GIF instead of PNG, simply use one of these:
convert some.pdf[15-19] some.jpg
convert some.pdf[15-19] some.gif
By default ImageMagick will use a resolution of 72 PPI. This will indirectly determine the image dimensions of the PNG/JPEG/GIF output. Should you need other output dimensions than the defaults, you have different options, for example:
- either add `-density`
- or add `-resize`
to the command line:
convert -density 200 some.pdf some.png
convert some.pdf -resize 50% some.png
Problem
How can I make a screenshot from every page of PDF file and save result as images in PHP? Is it possible?