4

I have a serie of ten images. I would like to have them stretched to fit 5in squares centered in a single A4 PDF, one image per page.

I would need something working on Mac (in case of some local command line subtleties).

5
  • I use pdfimages command from poppler-utils package in debian. Aug 28 '16 at 19:47
  • 2
    Could you expand to show what you've tried so far ? You've tagged it with imagemagick, have you tried the convert utility that comes with it, e.g. convert image01.jpg image02.jpg photo.jpg -compress jpeg -quality 75 test.pdf
    – steve
    Aug 28 '16 at 19:48
  • @steve I know that imagemagick could be used for that. I didn't tried much to be honest, as I don't know how to center or enforce the page size itself. Your command is putting all images in a PDF document but no size is given to them and the document is not A4
    – AsTeR
    Aug 28 '16 at 19:52
  • 1
    @PersianGulf pdfimages extracts raster images from PDF files. The OP wants the converse, to construct a PDF from a set of images. Aug 28 '16 at 20:11
  • 1
    Try having a play with ImageMagick's convert utility and its -page A4, -gravity center options. e.g. convert -page A4 image01.jpg image02.jpg image03.jpg -gravity center -format pdf test.pdf
    – steve
    Aug 28 '16 at 21:01
5

With ImageMagick, at 300 DPI:

convert -page 2480x3508 -extent 2480x3508 -density 300 -gravity Center *.png out.pdf

The "magic" numbers 2480x3508 are the dimensions in pixels of an A4 page at 300 DPI. See here for the dimensions at other resolutions if you need something different than 300 DPI and you can't be bothered to do the scaling yourself. Add -background black to get the images on black.

4
  • +1 for a nice ImageMagic solution that works without GUIs and even works on a RaspberryPi
    – polemon
    Aug 29 '16 at 8:57
  • i love that you care about explaining the "magic number". Thanks for that, this is exactly what I am looking for (and purely command line based), could you please add a conversion of all images to the right resolution before I accept?
    – AsTeR
    Aug 31 '16 at 10:01
  • @AsTeR What you want to do for PDF is adapt the resolution to the size of the images, rather than scale the images to a made-up resolution. shrug Sep 1 '16 at 5:16
  • I need them to take a limited space on the page, I should adjust with "extent"?
    – AsTeR
    Sep 2 '16 at 11:39
4

◉ Using Terminal Emulator + Preview Application

Follow the steps below:

○ Change hight and width to 5"x5" and PDF format

The built-in command you have on MacOS X for scriptable image processing, is called sips (BSD Command).

5"x5" is equal to 300x300 pixels.

Let's pretend we have thousands of *.jpg files in our current directory, and We want them all to be converted to 5"x5" *.pdf files and be saved in ~/Downloads/Test directory, all we should do is:

$ for i in *.jpg; do sips -s format pdf -p 300 300 $i --out ~/Downloads/Test/$i.pdf; done

Done! Now it's Preview's turn ↴

○ Center 5"x5" *.pdf files in a single A4 PDF

Go to ~/Downloads/Test, use ⌘A to select all files, now Open them With Preview, then use ⌘P, then change the Paper Size to A4, Check the Scale instead of Scale to Fit option, and use use 100% for scale. Now Save it as a new PDF file.

enter image description here

Voila! Here is your desired PDF file.

1
  • Thanks for this, it's not pure command line but that is cool!
    – AsTeR
    Aug 31 '16 at 10:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.