mackstann
mackstann

Reputation: 1367

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.

Upvotes: 65

Views: 40882

Answers (5)

tricasse
tricasse

Reputation: 1417

When you'll print them, your printer will probably not use more than 300 DPI, so you can save space (and printer processing time) by turning them to that resolution using -density 300x300.

You'll also probably want the PDF to match the paper size, no matter what the input files' sizes may be (and the original aspect ratio preserved), by using -resize and -extent with the paper size in pixels (and align them as you'd like with -gravity).

You may also want to put all of them in portrait mode by using -rotate "90>".

So here's my proposal:

$ convert *.jpg \
    -rotate "90>" \
    -gravity center \
    -units PixelsPerInch -density 300x300 \
    -resize 2551x3295 -extent 2551x3295 \
    foo.pdf

For US Letter, use 2551x3295; for A4, use 2480x3508.

Upvotes: 2

SebMa
SebMa

Reputation: 4709

According to this, 72 dpi is the default density => one dot per pixel (for a computer screen).

So you just need to specify -units pixelsperinch.

You can type the following command :

$ convert *.jpg -units pixelsperinch -page letter foo.pdf

BTW : If you want to use a non standard page size such as A4R for example, you must first determine the page size in dots (or pixels given at 72dpi) :

$ paperconf -s -p A4
595.276 841.89

Then the -page argument for A4R will be 842x595

Upvotes: 0

Forest
Forest

Reputation: 671

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.

Upvotes: 57

apurkrt
apurkrt

Reputation: 539

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

Upvotes: 16

Kurt Pfeifle
Kurt Pfeifle

Reputation: 90213

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

Upvotes: 10

Related Questions