Page 1 of 1

Convert picture to PDF with A4 fitting

Posted: 2018-01-03T09:34:34-07:00
by Antjac
Hi,

I would like to convert some image files to PDF by using convert.exe.
But, I can't fit the picture to a A4 format PDF (picture is always cropped or very smart...)

Actually I use this code :

Code: Select all

convert -density 300 -page A4 mypicture.jpg myfile.pdf
The size of the picture is : 1700 × 2338 pixels

How can I do ?

Re: Convert picture to PDF with A4 fitting

Posted: 2018-01-03T09:57:32-07:00
by snibgo
Either "-crop" or "-extent" your image to make it 1:sqrt(2) format, and use the "-density" setting to make the result A4, which is 297mm x 210mm.

Re: Convert picture to PDF with A4 fitting

Posted: 2018-01-04T00:28:04-07:00
by Antjac
Could you give me an example of command syntax ?

Re: Convert picture to PDF with A4 fitting

Posted: 2018-01-04T02:28:43-07:00
by snibgo
Assuming p.png is 1700 × 2338 pixels:

1700 * sqrt(2) is 2404.163056034262, so we'll make the height 2404 pixels.

2404 pixels in 297mm, 29.7 cm, is 80.9428 pixels per centimetre.

Code: Select all

convert p.png -gravity Center -extent 1700x2404 -density 80.9428 -units pixelspercentimeter p.pdf

Re: Convert picture to PDF with A4 fitting

Posted: 2018-01-04T02:49:24-07:00
by Antjac
Ok, is there a way to automatically detect the size of the picture and resize to A4 ?

Re: Convert picture to PDF with A4 fitting

Posted: 2018-01-04T03:25:47-07:00
by Bonzo
Ok, is there a way to automatically detect the size of the picture and resize to A4 ?
What version of Imagemagick are you using?

You might be better off writing a script to get and calculate the dimensions and passing the dimensions as variables into the Imagemagick command.

Re: Convert picture to PDF with A4 fitting

Posted: 2018-01-04T06:23:15-07:00
by Antjac
Actually : 7.0.6 but i can update

Re: Convert picture to PDF with A4 fitting

Posted: 2018-01-04T06:47:52-07:00
by snibgo
With v7, you can use "magick" instead of "convert", and use "%[fx:]" expressions instead of 2404 etc.