Scale an image to fit on A4 pdf-file, with some margins
Posted: 2011-09-24T14:29:29-07:00
Hello,
I'd like to convert an image from arbitrary size to pdf
so that it fit «almost» an A4 paper (I make a little margin
so that the image can be printed without loss on the edges)
For example, I create an image from scratch with these
dimensions:
$ convert -size 100x100 gradient:red-blue gradient.png
The width of an A4 is 595 pt; to get the correct size,
I calculate:
actual size / wished size * 72
100*72/595 = 12.1
$ convert -density 12.1 gradient.png gradient.pdf
$ grep -a Box gradient.pdf
/MediaBox [0 0 595.041 595.041]
/CropBox [0 0 595.041 595.041]
To get some margins, I do 100*72/538 = 13.4
$ convert -density 13.4 gradient.png gradient.pdf
$ grep -a Box gradient.pdf
/MediaBox [0 0 537.313 537.313]
/CropBox [0 0 537.313 537.313]
Now, I'd like to get a PDF with the «canonical» size of
595x842 pt, with the image correctly scaled centered on it,
and white margins around it. How to do that ?
Thanks in advance,
G.
I'd like to convert an image from arbitrary size to pdf
so that it fit «almost» an A4 paper (I make a little margin
so that the image can be printed without loss on the edges)
For example, I create an image from scratch with these
dimensions:
$ convert -size 100x100 gradient:red-blue gradient.png
The width of an A4 is 595 pt; to get the correct size,
I calculate:
actual size / wished size * 72
100*72/595 = 12.1
$ convert -density 12.1 gradient.png gradient.pdf
$ grep -a Box gradient.pdf
/MediaBox [0 0 595.041 595.041]
/CropBox [0 0 595.041 595.041]
To get some margins, I do 100*72/538 = 13.4
$ convert -density 13.4 gradient.png gradient.pdf
$ grep -a Box gradient.pdf
/MediaBox [0 0 537.313 537.313]
/CropBox [0 0 537.313 537.313]
Now, I'd like to get a PDF with the «canonical» size of
595x842 pt, with the image correctly scaled centered on it,
and white margins around it. How to do that ?
Thanks in advance,
G.