According to this question, How can I convert a series of images to a PDF from the command line on linux?, ImageMagick can convert multiple images to a single PDF.
How could I reverse the operation and convert a PDF of several pages to multiple images?
I have tried the following command, but I got the errors shown:
$ convert test.pdf test-%02.png
convert-im6.q16: attempt to perform an operation not allowed by the security policy `PDF' @ error/constitute.c/IsCoderAuthorized/408.
convert-im6.q16: no images defined `test-%02.png' @ error/convert.c/ConvertImageCommand/3258.
gs
was installed:
$ gs --version
9.26
Ubuntu version:
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 19.04
Release: 19.04
Codename: disco
Interestingly enough ImageMagick under 19.04 (and other Ubuntu releases!) disables many ghostscript format types. This can be seen in this snippet from
/etc/ImageMagick-6/policy.xml
:Of course I have added the arrow to catch your attention :). Modify this arrowed line to:
You can use your favorite text editor to accomplish this, using elevated privileges, or perhaps simply use the following
sed
one-liner:And then all should be well, I have tested this comprehensively on my own 19.04 VM where the conversion you are after works flawlessly...
If you wish to change the settings back to the default the following one liner will restore the backup file created in the run with
sed
:How cool is the command line!
Another reason for getting that same error is that the source images are too wide, too tall or too heavy.
The
/etc/ImageMagick-6/policy.xml
file controls what is acceptable as an image. Maximum width and height are set like this:10KP stands for 10000 pixels. If your image is larger than that running
identify
will not show the image info in the terminal and the image is basically out of reach for Image Magick.Other common properties that affect images being available or not are:
memory
,map
,area
anddisk
.Here the document describing
policy.xml
: https://imagemagick.org/script/security-policy.php+1 on all of the above.
Also note that my Docker container didn't have
gs
(Ghostscript) installed, so a very similarconvert-im6.q16: no images defined
error message is thrown in that case.