Information provided by ministries and agencies related to COVID-19 has many pdf files, and when sharing information, it is difficult to manually convert it to an image in order to visualize a large number of pages, so I created a plug-in.
Share the information below.
GIMP is a free and open source image editing software. https://www.gimp.org/
〇 When manually converting from pdf to png (1) Start GIMP.
(2) Drag and drop the pdf file to display the dialog. Click [Import]. (You can also open it by selecting [File]-[Open / Import])
The pdf will be read as an image. Each page is loaded as a layer.
(3) Export with the extension png from [File]-[Export As ...]. Only the image at the top of the layer is exported here. Repeat this each time, hiding the layer.
〇 When automatically converting from pdf to png (1) First, check if the python plugin is available. https://docs.gimp.org/2.10/ja/gimp-filters-python-fu.html This is also for reference. https://www.ibm.com/developerworks/jp/opensource/library/os-autogimp/index.html
You can use it if you have [Python-Fu] in [Filter]. If not, please do your best. (I'm sorry. Maybe something to do at the time of installation. I was on my own.)
(2) Write the code and save it in the plugin folder.
export_pdf2png.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
from gimpfu import *
import os
def export_pdf2png(img, drw, path):
img = img.duplicate()
for layer in img.layers:
layer.visible = False
for idx, layer in enumerate(img.layers):
layer.visible = True
filename = '{0}{1}.png'.format('PDF2PNG', idx)
fullpath = os.path.join(path, filename)
layer_img = img.duplicate()
layer_img.flatten()
pdb.file_png_save(img, img.layers[idx], fullpath, filename, 0, 9, 0, 0, 0, 0, 0)
register(
"python-fu-export-pdf2png",
"Export PDF to PNG",
"Exports pdf to png file",
"J",
"",
"",
"Convert from PDF to PNG...",
"*",
[
(PF_IMAGE, "img", "Input image", None),
(PF_DRAWABLE, "drw", "Input drawable", None),
(PF_DIRNAME, "path", "Output directory", os.getcwd())
],
[],
export_pdf2png,
menu="<Image>/File/"
)
main()
The plugin folder is set to [Edit]-[Settings]-[Folder]-[Plugins].
(3) Restart GIMP and check that it is registered in the [File] menu.
Import the pdf file with GIMP as you would manually.
Select [Convert PDF to PNG ...] from the [File] menu, specify the output destination folder, and execute.
Pages are output like this.
This is the output image (1st page).
I think that it may not work in the environment etc., so I'm sorry in that case. I hope it will be helpful for those in need.
Note: When you start the procedure browser from Help, the procedure information is displayed.
Recommended Posts