Image to PDF conversion

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
mariusz.pala
Posts: 2
Joined: 2014-06-05T06:42:47-07:00
Authentication code: 6789

Image to PDF conversion

Post by mariusz.pala »

Hi,

how can I convert an image (gif,jpg,tiff,png) to a PDF with A4 page size and image fit into the page with some margin defined?
RIght now the PDF size is the same as image size when I convert it.

Thanks in advance for any help,

Mariusz
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Image to PDF conversion

Post by fmw42 »

You will have to resize the image to the desired A4 size with margin subtracted. IM is a raster processor and will convert and image into raster format. If the output format is PDF, the image will be put into a vector shell, but will contain raster data. Thus you will not be able to interactively stretch the file without processing it to a different size via -density or -resize.

So you need to get the pixel dimensions of the A4, subtract the margin you want, then resize the image to that size and then add the appropriate border. see the page sizes at http://www.imagemagick.org/script/comma ... s.php#page

A4 is 595x842. If your margin is say 20 pixels. Then your need to resize to 575x823

Code: Select all

convert rasterimage -resize 575x823 -gravity center -background white -extent 595x842 image.pdf
mariusz.pala
Posts: 2
Joined: 2014-06-05T06:42:47-07:00
Authentication code: 6789

Re: Image to PDF conversion

Post by mariusz.pala »

Thank you! I found two problems with that command:
1. Smaller images are resized and I'd like to keep them in the original size.
- Solution was actually very simple, just use a different resize syntax: 575x823^>
2. PDF size is incorrect: 8.26x11.69inch, whether A4 generated from MS Word is 8.5x11inch
- According to this page (http://www.indigorose.com/forums/archiv ... 13334.html) it is actually a correct format.

So I should be fine! Thank you again!
Mariusz
Post Reply