Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImageMagick: convert image to PDF with A4 page size and image fit to page

I want to convert different image formats (bmp,jpg,gif,png,tiff-incluging multipaged) into a PDF format with A4 page size and with images fit to page (resized if necessary). Image should be positioned at the center of the page and I'd like to define an offset. I tried the code below but there is no offset at the top and the image quality is really poor.

convert png.png -gravity North -resize 500x500 -quality 100 -page a4x5x5 myout.pdf

Is there any way to do that?

Thanks in advance for any help, Mariusz

like image 516
Mariusz Pala Avatar asked Apr 22 '14 08:04

Mariusz Pala


3 Answers

If you want to keep the original resolution (lossless) you can try the following command:

convert png.png -background white -page a4 myoutput.pdf

Based on a comment posted before: https://stackoverflow.com/a/24573341/6747994

@m4tx This command only makes sense if the picture has a resolution above 500x800px, it does not zoom in, to avoid pixelated thumbnails.

like image 68
JoKalliauer Avatar answered Nov 10 '22 08:11

JoKalliauer


You can convert to pdf using ImageMagick

convert png.png myout.pdf

but use pdfjam instead of ImageMagick to adjust the page size

pdfjam --paper a4paper --outfile myoutA4.pdf myout.pdf

pdfjam offers other options, which may fit your needs.

like image 23
toliveira Avatar answered Nov 10 '22 09:11

toliveira


Found this somewhere on stackoverflow:

convert *.jpg -resize 1240x1753 \
                      -extent 1240x1753 -gravity center \
                      -units PixelsPerInch -density 150x150 multipage.pdf
like image 18
nomadSK25 Avatar answered Nov 10 '22 08:11

nomadSK25