Convert picture to PDF with A4 fitting

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
Antjac
Posts: 4
Joined: 2018-01-03T09:30:40-07:00
Authentication code: 1152

Convert picture to PDF with A4 fitting

Post by Antjac » 2018-01-03T09:34:34-07:00

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 ?

snibgo
Posts: 10365
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Convert picture to PDF with A4 fitting

Post by snibgo » 2018-01-03T09:57:32-07:00

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.
snibgo's IM pages: im.snibgo.com

Antjac
Posts: 4
Joined: 2018-01-03T09:30:40-07:00
Authentication code: 1152

Re: Convert picture to PDF with A4 fitting

Post by Antjac » 2018-01-04T00:28:04-07:00

Could you give me an example of command syntax ?

snibgo
Posts: 10365
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Convert picture to PDF with A4 fitting

Post by snibgo » 2018-01-04T02:28:43-07:00

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
snibgo's IM pages: im.snibgo.com

Antjac
Posts: 4
Joined: 2018-01-03T09:30:40-07:00
Authentication code: 1152

Re: Convert picture to PDF with A4 fitting

Post by Antjac » 2018-01-04T02:49:24-07:00

Ok, is there a way to automatically detect the size of the picture and resize to A4 ?

Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Convert picture to PDF with A4 fitting

Post by Bonzo » 2018-01-04T03:25:47-07:00

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.

Antjac
Posts: 4
Joined: 2018-01-03T09:30:40-07:00
Authentication code: 1152

Re: Convert picture to PDF with A4 fitting

Post by Antjac » 2018-01-04T06:23:15-07:00

Actually : 7.0.6 but i can update

snibgo
Posts: 10365
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Convert picture to PDF with A4 fitting

Post by snibgo » 2018-01-04T06:47:52-07:00

With v7, you can use "magick" instead of "convert", and use "%[fx:]" expressions instead of 2404 etc.
snibgo's IM pages: im.snibgo.com

Post Reply