Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make a screenshot every page of PDF file

How can I make a screenshot from every page of PDF file and save result as images in PHP? Is it possible?

like image 229
Newester Avatar asked Feb 18 '15 15:02

Newester


People also ask

How do you take a snapshot of multiple PDF pages?

Press the Print Screen button (usually between the letter and numeric keys) on the page you want to take a screenshot. Then open Microsoft Paint or other image editing program and press Ctrl + V (paste). Proceed similarly with other pages.

Can you add a screen shot to a PDF?

Convert Screenshot to PDF with Wondershare PDF Converter Launch Wondershare PDF Converter Pro, go to the "File to PDF" tab, and you will be able to add a screenshot into this converter using the "Add" button. Click the "Add" button, browse screenshots in your local folder, and click "Open" to add screenshot files.


1 Answers

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:

  1. either add -density
  2. or add -resize

to the command line:

convert -density 200 some.pdf some.png

convert some.pdf -resize 50% some.png
like image 54
Kurt Pfeifle Avatar answered Nov 02 '22 11:11

Kurt Pfeifle