png to pdf always fits height to 1 page

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
noelegdip
Posts: 4
Joined: 2013-07-10T08:15:02-07:00
Authentication code: 6789

png to pdf always fits height to 1 page

Post by noelegdip »

I am using imagemagick on a linux box running centos. I have png images that I am converting to pdf files.

An example size of a png in pixels would be 943x3331 (widthxheight) . When I convert this to a pdf it always keeps the pdf on one page so I am left with the image as a thin stripe down the middle of a pdf. I would like to be able to convert the pdf so it fits the png to the width of the page and goes down as many pages as needed for the height. Is this possible?
User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

Re: png to pdf always fits height to 1 page

Post by GreenKoopa »

This is possible. You would have to -crop the image into tiles before saving the image as a pdf.
noelegdip
Posts: 4
Joined: 2013-07-10T08:15:02-07:00
Authentication code: 6789

Re: png to pdf always fits height to 1 page

Post by noelegdip »

Just to check are you saying that I need to crop the png into sizes that will each fit a page and then convert all of these into a pdf?
User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

Re: png to pdf always fits height to 1 page

Post by GreenKoopa »

Break the input png into page sized tiles using -crop, then output to pdf. Something like:

Code: Select all

convert -size 943x3331 gradient: in.png
convert in.png -crop 950x1200 +repage out.pdf
There are many ways to crop and to position the tiles on the pages.
noelegdip
Posts: 4
Joined: 2013-07-10T08:15:02-07:00
Authentication code: 6789

Re: png to pdf always fits height to 1 page

Post by noelegdip »

but there is no setting that will convert a png to a pdf of more than one page?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: png to pdf always fits height to 1 page

Post by fmw42 »

GreenKoopa wrote:convert in.png -crop 950x1200 +repage out.pdf
He is suggesting that you crop the image into horizontal strips of height equal to one proper page. Then output the cropped sections to separate PDF pages.

see
http://www.imagemagick.org/Usage/crop/#crop_tile
http://www.imagemagick.org/Usage/crop/#crop_equal
User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

Re: png to pdf always fits height to 1 page

Post by GreenKoopa »

noelegdip wrote:but there is no setting that will convert a png to a pdf of more than one page?
Not that I know of. ImageMagick is not specifically a pdf or page layout tool. My example created a png of the size you gave, then created a pdf with that image split over 3 pages. It's not a setting, but it accomplished the same output with little complexity. Try that second line on your image and let us know what specifically more you want it to do.
noelegdip
Posts: 4
Joined: 2013-07-10T08:15:02-07:00
Authentication code: 6789

Re: png to pdf always fits height to 1 page

Post by noelegdip »

thanks for all your help in this and it worked. i used

convert test.png -crop 943x1360 +repage sample.pdf

I have a perfect 5 page pdf and am very happy. pat on the back for you and all that kind of thing.
Post Reply