When I convert a png-image to pdf, I have been using convert in.png -page A4 out.pdf
to get a pdf where the image quality is retained and the image is aligned to the bottom left corner by default. To align it to the center, I can add -gravity center
.
However, I recently discover that when trying convert in.png -gravity center -page A4 out.pdf
with an image that has larger dimensions than an A4 sheet, the top right corner of the image will be centred in the pdf and much of the image is cropped as it only fills the bottom left corner of the pdf. Without -gravity center
everything works as expected and the image is resized and fills the pdf starting from the lower left corner of the pdf while retaining what seems to be full resolution.
I have tried this suggestion and different combinations of -density
, -extent
, -quality
, and resize
, but I can't get the image centred with full resolution. The closest I have gotten is convert in.png -gravity centre -page A4 -resize 595x842 out.pdf
, which centres and resizes the image, but reduces quality substantially.
When the image is larger than the pdf output size, how should I use convert
to create a pdf of fixed size where the image is resized to fit the pdf, centred and retains full resolution?