劳整理+详细记录:十部高分印度悬疑电影推荐,反转+烧脑

如何转换 PDF 文件为Image (PNG, JPEG)图形化用GIMP命令行用pdftoppm工具

文本是译文。
原文:https://www.linuxuprising.com/2019/03/how-to-convert-pdf-to-image-png-jpeg.html

例子:按比例转换为宽度1024像素的图片:
pdftoppm -jpeg -scale-to 1024 $file filename

使用GIMP将PDF转换为图像(PNG、JPEG等)

GIMP是一个针对Linux、Windows和macOS的免费开源图像编辑器,可以将PDF文档的页面导出为各种图像格式,包括PDF、JPEG、TIFF、BMP等。

使用GIMP打开PDF文档时,每个页面都作为单独的层添加,一次只能将一个PDF页面导出为图像。您可以通过使用GIMP插件一次性将所有PDF页面(GIMP层)或选定的一组层导出为单独的图像。

使用GIMP将一个或几个PDF页面转换为PNG、JPEG和其他图像格式。

让我们从使用GIMP将单个(或仅几个)PDF页面转换为PNG、JPEG等开始,这不需要安装任何插件。从GIMP文件菜单中单击打开并选择PDF文件。将弹出“从PDF导入”对话框-确保“打开页面为”选项设置为“层”,然后单击“导入”:

原英文:
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:
GIMP Import from PDF dialog
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:
GIMP Layers
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:
Linux:
GIMP 2.8: ~/.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
macOS:
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:
GIMP export all layers as PNG images
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:
GIMP export selected PDF layers to PNG
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:
GIMP Exporting layers as PNG images
For more about customizing the export using Export Layers, visit the plugin documentation page.
You might also be interested in: Configure GIMP 2.10 To Use Photoshop Keyboard Shortcuts (How-To)
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:
sudo apt install poppler-utils
Fedora:
sudo dnf install poppler-utils
openSUSE:
sudo zypper install poppler-tools
Arch Linux:
sudo pacman -S poppler
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:
pdftoppm -png document.pdf document
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:
pdftoppm -png -f 5 -l 15 document.pdf document
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:
pdftoppm -png -rx 300 -ry 300 document.pdf document
To see all the options supported by pdftoppm, run pdftoppm –help and man pdftoppm.

 

京ICP备11047313号-21