Before you keep reading, there is an assumption made that you are using
a GNU/Linux operating system with 'imagemagick' and 'ghostscript'
packages installed.
Last updated: 2023/01/05
How to Fix ImageMagic vs PDF Conversion Issue
---------------------------------------------
If you are having issues using 'ImageMagic' package, the commands being
'convert' or 'mogrify', to convert to or from a PDF, you you may need
to open the '/etc/ImageMagick-6/policy.xml' file, or something similar,
and change the line that says:
to:
...and that should fix the issue. Though if you are concerned about the
security-related issues because of Ghostscript, you only need to worry
about it if your 'ghostscript' package version older than 9.24. Use
'ghostscript --version' to find out.
Now that that is solved...
--------------------------
You use 'ImageMagic' like so to convert an image to a PDF:
convert input.ext output.pdf
You use 'ImageMagic' like so to convert a PDF to an image or multiple
images:
convert input.pdf output.ext
HOWEVER, though you still need to solve the issue like previously
mentioned, you can use a program called 'Converseen' to have a graphical
way to batch convert multiple images to a PDF or from a PDF. Converseen
uses 'ImageMagick' which is why you still may need to do the mentioned
fix.
Still having trouble?
---------------------
Honestly, the easiest way to convert multiple images to a PDF is to
make sure that they are all JPG with the same file extension (*.jpg)
and then use 'img2pdf' package to create the PDF like so since it
does not seem to rely on ImageMagick at all (it's Python-based):
cd '/path/to/images/folder'
find . -type f -iname "*.jpg" -exec img2pdf --output out.pdf {} +
...and if you want to then have that PDF encrypted, use the 'pdftk'
package like so:
pdftk input.pdf output output.pdf user_pw PASSWORD
...and yes, the "output" part is correct as for whatever reason,
you do not use "--output" like you normally would with many other
conversion programs.
You can install 'img2pdf' and 'pdftk' using one of the following on a
GNU/Linux system:
sudo apt install img2pdf pdftk
Or, if you have Python's PIP installed...
sudo pip[3] install img2pdf
...and then worse case compile 'pdftk' from source from
https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/
Absolute "worse-case scenario," you could use software such as 'GIMP' to
import a bunch of images as layers and then export as a PDF with each
layer as a page. There is also a desktop publishing program called
'Scribus' in which you could place an image on each page; however,
neither of these are very useful when you have a folder loaded with
images and time is an issue.
And if all you want to do is extract images from a PDF, you can use the
'poppler-utils' package's 'pdfimages' command like so:
pdfimages -j '/path/to/doc.pdf' image
...If the PDF document is encrypted, use:
pdfimages -opw "Password" -j '/path/to/ecrypted/doc.pdf' image
The "image" part at the end tells 'pdfimages' to output the images as
"image-###", in which the "###" part is the image number extracted.
Just remember though, unless the PDF is just a bunch of JPEG files,
using 'pdfimages' will not extract any text, you will have to use the
'pdftotext' command for that.