I have requirement of converting PDF pages to images. There is a background image with some text in my file, and when I save it as an image only the background image gets saved.
Is there any software available for the same so that complete page can be converted to an image?
You can use
pdftoppm
from thepoppler-utils
package to convert a PDF to a PNG:This will output each page in the PDF using the format
outputname-01.png
, with01
being the index of the page.Converting a single page or a range of pages of the PDF
Change
{page}
to the page number. It's indexed at 1, so-f 1
would be the first page.If you'd like to work on a range of pages, you can also specify a number for the flag
-l
(last page), so having-f 1 -l 30
would specify the pages from 1 to 30.Note again that
.png
will be appended tooutputname
automatically, so there's no need to include the extension. Also,-singlefile
removes the-01
suffix cited above, since the output is known to have only one file.Specifying the converted image's resolution
The default resolution for this command is 150 DPI. Increasing it will result in both a larger file size and more detail.
To increase the resolution of the converted PDF, add the options
-rx {resolution}
and-ry {resolution}
. For example:Install imagemagick.
Using a terminal where the PDF is located:
For the full document:
For a single page:
Whereby:
PNG, JPG or (virtually) any other image format can be chosen.
-density xxx
will set the DPI toxxx
(common are 150 and 300).-quality xxx
will set the compression toxxx
for PNG, JPG and MIFF file formates (100 means no compression).[666]
will convert only the 667th page to PNG (zero-based numbering so[0]
is the 1st page).All other options (such as trimming, grayscale, etc.) can be viewed on the website of Image Magic.
IIRC GIMP is capable of using PDFs, i.e. converting them into images. So if you want to edit the images right away - GIMP is your friend.
The currently accepted answer does the job but results in an output which is larger in size and suffers from quality loss.
The method in the answer given here results in an output which is comparable in size to the input and doesn't suffer from quality loss.
TLDR - Use
pdfimages
:pdfimages -j input.pdf output
Quoting the linked answer:
If your pdfs are scanned, the images are already stored as part of pdf. you will simply need to extract them with
pdfimages
:If you only want to convert a specific page of a PDF to a PNG, you can pipe
pdftk
toconvert
(described above) like this:You can use convert and specify a higher density using
-density
option.eg.
convert -d 300 foo.pdf bar.png
To get a single page from gm convert, add [N] (with N the page number starting at 0) to the PDF name, ie
gm convert foo.pdf[11] out.png
to get the 12th page from the PDF.For
pdftoppm
use-f N -singlefile
, where N is the page number starting at 1, iepdftoppm -f 12 -singlefile foo.pdf out
for the same result. It appears to always add ".png" to the output filename and there is no way to stop this.Master PDF Editor (ver 2.2) has this option built in. Open the PDF file and then go to File > Export to > Images. It presents a dialog where you can define different options for the output. Extremely useful. Hope this info helps.
PDF Mod also allows exporting images of all or individual pages of PDF files.