How to manage image placement when converting to pdf with imagemagick?

Viewed 2833

I have a bunch of png's ripped from github, that look kind of like this:

enter image description here

All have a width of 912, but the heights vary.

I'm trying to convert them all to a nice readable A4 pdf, using:

convert -page A4 *.png -format pdf file.pdf

I can get them all into the pdf, but can't get the results quite right:

  • It puts them on the bottom instead of the top of the page.
  • Also, most of them fit on one page, but for the ones with lots of pixels going down, I'd like to split and crop it so it spans multiple pages while keeping a consistent size

How do I get them on the top of the page (centered, or left-justified with a bit of margin), and bonus points for splitting them?

2 Answers

Instead of calculating you could use the -gravity parameter. I would suggest "-gravity north" to stick the images to the top margin or "-gravity center" to center them. Results vary depending on if the image fits properly into the page. If they are all about the same size it should work.

So if you are in the folder where all your png:s are i would do the following: convert -gravity north -page A4 *.png -format pdf output.pdf

Related