I'm using imagick to convert a png to pdf:
convert file.png file.pdf
Now I get a pdf with only one page and have a problem with printing that pdf.
Is it possible to automatically split png to create pdf with pages fitted to A4 format?
Not 100% sure how/where you want to split your large PNG image, but this should give you some ideas. First, let's determine a very approximate size for a sheet of A4 - some printers are borderless and some can't get near the edges of the paper, so if we say, for argument's sake, A4 is 8 inches by 11, then at 144 dpi (also a guess) you will get around 1,152 pixels by 1,584 pixels on a page of A4.
So, we hack your image into lumps no bigger than that, and repage them so they forget where they came from in the original image. We then save the resulting A4-sized chunks as page000.png, page0001.png etc.
convert image.png -crop 1152x1584 +repage page%03d.png
Now we can put them all back together as a PDF with this
convert -density 144 page*png result.pdf
Obviously this simple method has no concept of where is a sensible place to chop your image so it may go around cutting at unfortunate places!
As commented by @Danack, you can obviate the need for the intermediate files and go straight to the output PDF like this:
convert image.png -crop 1152x1584 +repage output.pdf
Let's try it out. First create a big gradient PNG
convert -size 3000x4000 gradient:black-white image.png

Now chop that puppy up...
convert image.png -crop 1152x1584 +repage page%03d.png
that gives 9 pages like this:
identify page*
page000.png PNG 1152x1584 1152x1584+0+0 16-bit sRGB 9.68KB 0.000u 0:00.000
page001.png[1] PNG 1152x1584 1152x1584+0+0 16-bit sRGB 9.68KB 0.000u 0:00.000
page002.png[2] PNG 696x1584 696x1584+0+0 16-bit sRGB 8.3KB 0.000u 0:00.000
page003.png[3] PNG 1152x1584 1152x1584+0+0 16-bit sRGB 9.71KB 0.000u 0:00.000
page004.png[4] PNG 1152x1584 1152x1584+0+0 16-bit sRGB 9.71KB 0.000u 0:00.000
page005.png[5] PNG 696x1584 696x1584+0+0 16-bit sRGB 8.32KB 0.000u 0:00.000
page006.png[6] PNG 1152x832 1152x832+0+0 16-bit sRGB 5.21KB 0.000u 0:00.000
page007.png[7] PNG 1152x832 1152x832+0+0 16-bit sRGB 5.21KB 0.000u 0:00.000
page008.png[8] PNG 696x832 696x832+0+0 16-bit sRGB 4.48KB 0.000u 0:00.000
And put them back together, as a PNG for display here, but the Pdf is no different:

An alternative way is to tell ImageMagick to do the cropping to a tileset
convert -crop 1x16@ AHw1w.png -page 200x100 tile.pdf
This splits the input image into 16 sections high, and 1 across, and then renders them onto a pdf for which the pages are sized 200 by 100.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With