Scaling various images to A4 size including borders

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
tps800
Posts: 2
Joined: 2019-07-19T02:41:18-07:00
Authentication code: 1152

Scaling various images to A4 size including borders

Post by tps800 »

Hi!

I am trying to scale and rotate various images to A4 size, then convert them to PDF and print them. But it does not work in any way reliable. Sometimes the images are printed as expected, sometimes they are rotated if not necessary. Most of the time the images are positioned with their left upper corner within the center of the page. Whatever I try it does not lead to what i'd like to have:
  1. make them portrait: shorter sides top and bottom, longer sides left and right.
  2. scale them to fit on A4, respecting borders all 1cm.
I've come as far as:

Code: Select all

/usr/bin/convert "file.png" -verbose -strip -background white -rotate "90>" -trim +repage -page "A4<" -gravity "center" -resize "98%>" PDF:file.pdf
Most of the time I get:
https://drive.google.com/file/d/1mTR5zZ ... sp=sharing

Any idea how I could get what I want: this image centered with a border of 1cm on A4 paper?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Scaling various images to A4 size including borders

Post by fmw42 »

Post an input image so we can test with your command and then correct it.

Try replacing -page "A4<" with -resize WxH for the WxH corresponding to A4.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Scaling various images to A4 size including borders

Post by fmw42 »

Try this

Code: Select all

convert -size 1000x842 pattern:checkerboard -background black -rotate "90>" -trim +repage -resize "595x842>" -gravity center -extent 595x842 result.png
If that works, replace the -size 1000x842 pattern:checkerboard with your image and then replace result.png with your file.pdf

I don't think you need the -trim +repage, but it won't hurt to leave it.
Post Reply