Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I control PDF paper size with ImageMagick?

I have 16 jpg files which are around 920x1200 pixels (the widths slightly differ but heights are all 1200). I'm trying to join them into a pdf with:

convert *.jpg foo.pdf

But the resulting paper size is 1.53x2 inches. If I pass the arguments -page Letter, the page size ends up being a bewildering 1.02x1.32 inches. What is going wrong here? All of the information I can find suggests that this should work. I just want a document that consists of 16 letter-size pages.

like image 408
mackstann Avatar asked Jul 27 '12 17:07

mackstann


3 Answers

This question is pretty old, but I had a similar problem and I think I found the solution.

The documentation for the -page option says "This option is used in concert with -density", but the relationship between the options seems a little unclear, possibly because the documentation is geared towards raster images.

From experimenting with the settings, I found that the pdf page size can be controlled by combining -page -density and -units. The documentation for -page shows that letter is the same as entering 612 x 792. Combining -density 72 with -units pixelsperinch will give you (612px /72px) * 1in = 8.5in.

convert *.jpg -units pixelsperinch -density 72 -page letter foo.pdf should do what the original poster wanted.

like image 77
Forest Avatar answered Sep 28 '22 05:09

Forest


I just succeeded with convert file.mng -page letter file.pdf

like image 27
apurkrt Avatar answered Sep 28 '22 04:09

apurkrt


For Letter, you need to specify the size as 792x612 PostScript points. Therefor try this command:

 convert \
    in1.jpg \
    in2.jpg \
    in3.jpg \
    in4.jpg \
    in5.jpg \
   -gravity center \
   -resize 792x612\! \
    letter.pdf

Works for me with ImageMagick version 6.7.8-3 2012-07-19 Q16 on Mac OS X:

identify -format "%f[%s] :  %W x %H\n" letter.pdf
  letter.pdf[0] :  792 x 612
  letter.pdf[1] :  792 x 612
  letter.pdf[2] :  792 x 612
  letter.pdf[3] :  792 x 612
  letter.pdf[4] :  792 x 612

Or

pdfinfo -f 1 -l 5 letter.pdf 
  Title:          _
  Producer:       ImageMagick 6.7.8-3 2012-07-19 Q16 http://www.imagemagick.org
  CreationDate:   Fri Jul 27 22:28:00 2012
  ModDate:        Fri Jul 27 22:28:00 2012
  Tagged:         no
  Form:           none
  Pages:          5
  Encrypted:      no
  Page    1 size: 792 x 612 pts (letter)
  Page    1 rot:  0
  Page    2 size: 792 x 612 pts (letter)
  Page    2 rot:  0
  Page    3 size: 792 x 612 pts (letter)
  Page    3 rot:  0
  Page    4 size: 792 x 612 pts (letter)
  Page    4 rot:  0
  Page    5 size: 792 x 612 pts (letter)
  Page    5 rot:  0
  File size:      178642 bytes
  Optimized:      no
  PDF version:    1.3
like image 36
Kurt Pfeifle Avatar answered Sep 28 '22 04:09

Kurt Pfeifle