9

I have a series of images (a scanned book, actually) that I want to make into a PDF in A4 format.

Why I'm doing this: I'm helping a less computer savvy person in a different country to get a printed copy of this book. I know they have the ability to print PDFs, but I don't want to go through the hassle of figuring out and trying to explain how to resize and print a series of images. – I just want to email them something they can throw at a printer with a minimum of fuss.

2
7

I found a solution which uses ImageMagick, but it took me a while to figure out that I had to use the option -page A4 to generate an A4 formatted PDF. In the end this simple command did the trick for me:

convert *.gif -page A4 book.pdf

Troubleshooting

While googling for an answer I realized that other people also have tried this, and encountered problems which I never saw. These hints may be helpful to some of you.

Images of different sizes: If your images do not all have the same size, have a look at this YouTube video: “How to convert multiple images to A4 pdf using imagemagick”. The guy in the video uses the command (which he states produces A4 output):

convert *.jpg -resize 595x842 -gravity center -background white \
    -extent 595x842 resultimage.pdf

Postamble

This question has been brought up on stackoverflow, but closed as off topic (“How can I convert a series of images to a PDF from the command line on linux?”). As this gave me a hint, but not the full solution I'm creating (and answering) this question here, in the hope that someone else will find it useful, too.

7

Use img2pdf:

img2pdf --pagesize A4 file1.jpg file2.jpg > book.pdf

From its description:

Losslessly convert raster images to PDF without re-encoding JPEG and JPEG2000 images. This leads to a lossless conversion of JPEG and JPEG2000 images with the only added file size coming from the PDF container itself.

ImageMagick on the other hand will decode and re-encode the JPEG data, resulting in generation loss and performance 10–100 worse than img2pdf.

2
  • what about PNG? – vstepaniuk May 17 '20 at 8:26
  • Found in man img2pdf: > Losslessly convert raster images to PDF without re-encoding PNG, JPEG, and JPEG2000 images. This leads to a lossless conversion of PNG, JPEG and JPEG2000 images with the only added file size coming from the PDF container itself. Other raster graphics formats are losslessly stored using the same encoding that PNG uses. Since PDF does not support images with transparency and since img2pdf aims to never be lossy, input images with an alpha channel are not supported. – vstepaniuk May 17 '20 at 8:35
-1

Using convert, an image format converter from the project Image Magick and define the paper size with the parameters -density and -resize:

convert file?.jpg -gravity center -resize 612x792! -units PixelsPerInch -density 72x72 book.pdf

1
  • Welcome to Super User! Please read How to recommend software for minimum required information and other suggestions on how to recommend software on Super User. To keep your answer useful even if included link(s) breaks please edit these details into your answer. Without knowing what convert is this answer is not useful. – I say Reinstate Monica Nov 19 '18 at 2:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.