- Convert multipage PDF to PNG and back (Linux)
- 2 Answers 2
- Future is here!
- Future is here!
- Convert PDF to PNG, JPEG in Ubuntu
- How to convert pdf to image on Linux command line
- How to convert pdf to image on Linux command line
- Converting pdf to image on Linux
- Adding a border using Imagemagick to your image
- Transforming image to pdf format
- Putting it all together
- How To Convert PDF To Image (PNG, JPEG) Using GIMP Or pdftoppm Command Line Tool
- Convert PDF to image (PNG, JPEG, etc.) using GIMP
- Convert one or only a few PDF pages to PNG, JPEG and other image formats using GIMP.
- Using the GIMP Export Layers plugin to export all/select layers (PDF pages in this case) as separate images.
- Convert PDF to images (PNG, JPEG, more) from the command line using pdftoppm
Convert multipage PDF to PNG and back (Linux)
I have a lot of PDF documents that I want to convert to PNG, edit in Gimp, and then save back to the multipage Acrobat file. I’m filling out forms and adding scanned signature, trying to avoid printing, signing, then scanning back in, with the ability to type the information I need to enter.
I’ve been trying to use Imagemagick to convert to png files, which seems to work fine. I use the command convert -quality 100 -density 300×300 multipage.pdf single%d.png
(I’m not really sure if the quality parameter is right for png).
But I’m having problems with saving back to PDF. Some of the files have the wrong page size, and I’ve tried every command and procedure I can find, but there are always a few odd sizes. The resolution seems to vary so that it looks good at a certain zoom level, but either a few pages are specified at about 2″ wide, or they are 8.5×11 but the others are about 35″ wide. I’ve tried making sure Gimp had the canvass size and resolution correct, and to save the resolution in the file, but that doesn’t seem to matter.
The command I use to save the files is convert -page letter -adjoin single*.png multipage.pdf I’ve tried other parameters, but none seemed to matter.
If anyone has any ideas or alternatives, I’d appreciate it.
2 Answers 2
«I’m not really sure if the quality parameter is right for PNG.»
For PNG output, the -quality setting is very unlike JPEG’s quality setting (which simply is an integer from 0 to 100 ).
For PNG it is composed by two single digits:
The first digit (tens) is (largely) the zlib compression level, and it may go from 0 to 9 .
(However the setting of 0 has a special meaning: when you use it you’ll get Huffman compression, not zlib compression level 0. This is often better. Weird but true.)
The second digit is the PNG data encoding filter type (before it is compressed):
- 0 is none,
- 1 is «sub»,
- 2 is «up»,
- 3 is «average»,
- 4 is «Paeth», and
- 5 is «adaptive».
In practical terms that means:
- For illustrations with solid sequences of color a «none» filter ( -quality 00 ) is typically the most appropriate.
- For photos of natural landscapes an «adaptive» filtering ( -quality 05 ) is generally the best.
«I’m having problems with saving back to PDF. Some of the files have the wrong page size, and I’ve tried every command and procedure I can find [. ] but either a few pages are specified at about 2″ wide, or they are 8.5×11 but the others are about 35″ wide.»
Not having available your PNG files, I created a few simple ones with different dimensions to verify the different commands (as I wasn’t sure myself any more). Indeed, the one you used:
does create all PDF pages in (same) letter size, but it places my sample of (differently sized) PNGs always on the lower left corner of the PDF page. (Should a PNG exceed the PDF page size, it does scale them down to make them fit — but it doesn’t scale up smaller PNGs to fill the available page space.)
The following modification to the command will place the PNGs into the center of each PDF page:
If this is still not good enough for you, you can enforce a (possibly non-proportional!) scaling to almost fill the letter area by adding a -scale ‘590!x770!’ parameter (this will leave a border of 11 pt at each edge of the page):
To leave away the extra border, use -scale ‘612!x792!’ . — Should you want only upward scaling to happen if required while keeping the aspect ratio of the PNG, use -scale ‘590 :
Источник
Future is here!
Future is here!
Convert PDF to PNG, JPEG in Ubuntu
PDF stands for Portable Document Format. It was developed by Adobe in the year 1993. In this article, we would discuss how to convert PDF to PNG, JPEG and various other image file formats in Ubuntu.
Since an image format like PNG, JPEG etc. is easily accessible. Therefore, we may think of converting our PDF to an image format before sharing it. Or, there could be some other reason.
First, we would install a package poppler-utils through standard Ubuntu repository. This would enable us to use the command-line utility – pdftoppm. Then, we would illustrate how to convert PDF to PNG, JPEG and various other image file formats.
Note: Following installation operations require you to have superuser privileges. In case you don’t have one, then we advise you to contact your System Administrator for assistance.
Install poppler-utils in Ubuntu
The package poppler-utils is available through standard Ubuntu repository. Therefore, first update the repository to make the latest version of the package available. Hence, open a terminal and issue the following –
Then, to install the package –
Now, lets say we have a PDF example.pdf (containing 25 pages). We will illustrate how to convert it in various image file formats. Various useful options which can be utilised with pdftoppm command-line utility are discussed next.
Convert PDF to PNG
The easiest way to convert all the pages of PDF to PNG is –
-png is the image file format the PDF is converted to,
N is the prefix for the output file and,
example.pdf is the
Output file name would be – (N-01.png; N-02.png ….)
Consider a scenario wherein we may specify the page range to convert –
-f number – first page to convert and,
-l number – last page to convert.
To convert only odd numbered pages –
To convert only even numbered pages –
To specify image resolution (default is 150 DPI) –
-r number – to specify image resolution (in this case it was 300 DPI)
Convert PDF to JPEG
All the options will remain the same, we just have to replace -png in the above code with -jpeg.
Convert PDF to gray (grayscale PGM)
Here also, all options will remain the same – we have to just replace -png in the above code with -gray.
Convert PDF to mono (monochrome PBM)
Similarly, just replace -png in the above code with -mono.
Convert PDF to TIFF
Again, replace -png in the above code with -tiff.
In conclusion, we have discussed how to convert PDF to PNG, JPEG and various other image file formats.
Источник
How to convert pdf to image on Linux command line
How to convert pdf to image on Linux command line
Tools needed to transmute pdfs to png/jpeg formats:
- Linux command line especially bash or any modern shell
- pdftoppm command – Portable Document Format (PDF) to Portable Pixmap (PPM) converter (image format).
- convert command – Convert between image formats and resize an image, blur, crop, despeckle, dither, draw on, flip, join, re-sample, and much more. We can use the same tool to convert images to pdf again.
- GIMP app – We can use the GIMP app to import PDF file and then export as PNG/JPG image format.
Converting pdf to image on Linux
Adding a border using Imagemagick to your image
Again the syntax is pretty straightforward to add a border using the Linux CLI:
$ convert -border
$ convert -border 20 -bordercolor Bulldog.pdf-1.png out-Bulldog.pdf-1.png
$ ls -l *Bulldog.pdf-1.png
$ xdg-open out-Bulldog.pdf-1.png
Click to enlarge
Transforming image to pdf format
Now that we have edited our image, it is time to build back pdf file. Let us create a new directory as follows using the mkdir command:
$ mkdir out
Transforming image to pdf format is simple:
$ convert manipulated -input-1.png input-2.png input-N.png out/output.pdf
$ convert out-Bulldog.pdf-1.png Bulldog.pdf-2.png Bulldog.pdf-3.png out/final-Bulldog.pdf
$ xdg-open out/final-Bulldog.pdf
Putting it all together
For a large number of files, you may want to write a shell script. Here is a handy bash for loop on my Ubuntu Linux desktop that I used:
Источник
How To Convert PDF To Image (PNG, JPEG) Using GIMP Or pdftoppm Command Line Tool
This article explains how to convert the pages of a PDF document to image files (PNG, JPEG, and others). For this task we’ll be using (you can choose the one you prefer):
- GIMP (GNU Image Manipulation Program): for those wanting to use use a graphical application for this task. Since by default GIMP can’t export all PDF pages automatically (it requires exporting pages one by one), the article also includes a GIMP plugin that can export all layers as separate images.
- pdftoppm: this command line tool is part of the poppler / poppler-utils package, and it can convert PDF documents to images (with each PDF page as a separate image) like PNG, JPEG and others. The tool can convert a single page of a PDF document, all the pages, or a page range, and it comes with multiple options like specifying the resolution, image cropping, and more.
Convert PDF to image (PNG, JPEG, etc.) using GIMP
GIMP, a free and open source image editor for Linux, Windows and macOS, can export pages of PDF documents to various image formats, including PDF, JPEG, TIFF, BMP, and many others.
When opening a PDF document with GIMP, each page is added as a separate layer, and only one PDF page at a time can be exported as an image. You can export all the PDF pages (GIMP layers) or a selected group of layers as separate images in one go by using a GIMP plugin.
Convert one or only a few PDF pages to PNG, JPEG and other image formats using GIMP.
Let’s start with converting a single (or only a few) PDF page as PNG, JPEG, etc., using GIMP, which doesn’t require installing any plugins. From the GIMP File menu click Open and choose the PDF file. An Import from PDF dialog should pop up — make sure the Open pages as option is set to Layers , and click Import :
In the GIMP layers dialog, scroll to the page you want to convert from PDF to PNG, JPEG and so on, and drag it with the mouse cursor to the top so it’s the first layer:
Next, from the GIMP File menu click Export As. . In the export dialog you can either change the exported filename extension to the desired image format (in the Name field at the top), or you can click Select File Type (By Extension) at the bottom of the dialog to choose the format that will be used for the exported PDF page:
Now all you have to do is press the Export button to save the PDF page as a PNG, JPEG, TIFF or some other image format.
Depending on the image type you’ll use for your exported PDF page, GIMP will show a dialog that lets you change some settings, like the image quality, compression level, and so on. Make any changes you want here, then click Export and the image file will be saved to your computer.
If you want to export other pages of the PDF document to an image, move the layer containing the page to the top of the layer list in GIMP, and repeat the process. For converting an entire PDF (or a large number of PDF pages in one go) to JPEG, PNG, and other image formats using GIMP, see the instructions below.
Using the GIMP Export Layers plugin to export all/select layers (PDF pages in this case) as separate images.
Export Layers is a GIMP plugin that can export layers as separate images. It can export layers in any file format supported by GIMP, and it comes with various options, like exporting all layers, only visible layers, exporting only selected layers, and more.
Download Export Layers plugin for GIMP.
You can easily install this plugin on Windows by using provided Windows installer. To install it on Linux or macOS, download the Export Layers ZIP archive, extract it, and copy the export_layers.py file and the export_layers folder to:
/.gimp-2.8/plug-ins
GIMP 2.10 installed using your Linux distribution’s package manager:
/.config/GIMP/2.10/plug-ins
GIMP 2.10 installed from the Flathub Flatpak package:
/.var/app/org.gimp.GIMP/config/GIMP/2.10/plug-ins
GIMP 2.10 installed using snap:
/snap/gimp/current/.config/GIMP/2.10/plugins
- GIMP 2.8: /Users/[your username]/Library/Application Support/GIMP/2.8/plug-ins
- GIMP 2.10: /Users/[your username]/Library/Application Support/GIMP/2.10/plug-ins
Restart GIMP if it was running when you installed the plugin.
More about installing the Export Layers GIMP plugin can be found in its documentation.
Now open a PDF file with GIMP and make sure the Open pages as option is set to Layers in the import dialog, as already explained above.
You can now convert all the PDF pages or a select group of pages to image formats like PNG, JPEG, and any other format supported by GIMP, by clicking File -> Export Layers. from the GIMP menu. In case you want to export all the PDF pages as separate PNG images, all you have to do is choose the save location and press the Export button.
The Export Layers dialog lets you change the file extension, as well as perform other advanced operations. Click the png field at the bottom of the dialog to change the image format:
For advanced options, click Settings at the bottom of the Export Layers dialog, and then Show more settings .
For example, if you want to only export the layers you select in the preview dialog (shown on the right-hand side of the Export Layers dialog), click + Add Constraint. , and then Only layers selected in the preview :
You can now click a layer in the right-hand side preview sidebar, then hold the Shift key and click another layer to select all layers in between. Or hold the Ctrl key and click on each layer you want to export.
All that remains to be done now is to click the Export button, and GIMP will start exporting the PDF pages you’ve selected (or all) to PNG, JPEG or whatever image format you chose:
For more about customizing the export using Export Layers, visit the plugin documentation page.
Convert PDF to images (PNG, JPEG, more) from the command line using pdftoppm
pdftoppm can convert PDF document pages to image formats like PNG, JPEG, and others, from the command line. In can convert all the pages of a PDF document to separate PDF files, a single page or a page range, it supports specifying the image resolution, scale, crop the resulting images, and much more.
pdftoppm is part of the poppler / poppler-utils / poppler-tools package (depending on the Linux distribution you’re using). Install this package as follows:
- Debian, Ubuntu, Linux Mint, and other Debian/Ubuntu-based Linux distributions:
- Fedora:
- openSUSE:
- Arch Linux:
In other Linux distributions use your package manager to install the poppler / poppler-utils package.
Now let’s start by using pdftoppm to convert an entire PDF (we’ll call it document.pdf in this example) to PNG, and name each page of the PDF converted to PNG as document-01.png , document-02.png and so on:
Want to convert the PDF pages to JPEG instead of PNG? Use -jpeg instead. For TIFF, use -tiff . If you don’t specify an image format, pdftoppm will convert the PDF pages to PPM image files by default.
To define a page range for the PDF to image conversion with pdftoppm, use -f N , where N in this case is the page number of the first page to print, and -l N , where N in this case is the last page to print.
For example to convert pages 5 to 15 from a PDF document (named document.pdf in the example) to PNG with pdftoppm, and have each resulting image named document-05.png , document-06.png and so on, you’d use:
Want to increase the converted image DPI? By default pdftoppm converts PDF pages to images with a DPI of 150. To increase the DPI, add -rx and -ry to the command, with your custom values.
For example, to use a DPI of 300 for the resulted images, use:
To see all the options supported by pdftoppm, run pdftoppm —help and man pdftoppm .
Источник