I have a 1200×7200 pixels PNG, and I want to slice it into a multipage PDF, 8.5×11 inches, with 1 inch margins.
For convenience, here is an inches-to-pixels table:
Inches Pixels, at 72 PPI Pixels, at 300 PPI 8.5 612 2550 11 792 3300
I tried
# version 1
magick input.png -crop x3300 +repage -units PixelsPerInch -density 300 output.pdf
but it doesn't leave margins.
Using trial and error, I came up to
# version 2
magick input.png -crop x2700 -repage 2550x3300+100+100 -units PixelsPerInch -density 300 output.pdf
but I cannot figure out why the text on the last page is moved to its bottom (to fix this, I tried to add -gravity center
, but this removes margins).
I also don't understand why, to create margins, the value 100
works for me. Because I use -units PixelsPerInch
and -density 300
, I expect that 1 inch is 300 pixels and not 100, but changing -repage 2550x3300+100+100
to -repage 2550x3300+300+300
makes the margins extremely large.
The image is uploaded here: https://github.com/jsx97/test/blob/main/input.png
And here is a visual representation of what I mean to achieve:
The opaque gray rectangles represent the sliced images. The red arrows represent 1-inch margins.
The image should extend from the top-left 1 inch margin to the bottom-left 1 inch margin. Except for the last page, of course, because the remaining height of the original image can be smaller than 9 inches.
Which version will be used, A or B, is not what the user decides. It simply depends on the image width and height.
I do understand text and images can be sliced at arbitrary height, and this is not a problem.
magick input.png [+repage] -resize 1950x\> -crop x2700 +repage -background white -extent 1950x2700 -bordercolor white -border 300x300 -units PixelsPerInch -density 300 output.pdf
The related discussion is on GitHub:
https://github.com/ImageMagick/ImageMagick/discussions/7402
+repage
after the input file is optional.