• About

N1nja Hacks

~ Random assortment of solutions, sneaky hacks and technical HOWTOs

N1nja Hacks

Tag Archives: printing

Printing Many Images of Fixed or Variable Size in Linux

08 Tuesday Oct 2013

Posted by valblant in Uncategorized

≈ Leave a comment

Tags

image processing, printing

I thought I’d share some things I learned recently after having to format and print hundreds of images automatically. I’ll discuss printing images of the same size, as well as printing images of different sizes.

The most difficult step in the process is to format the image on the page. This is very easy to do manually by using OpenOffice, for example, but how do you do it from command line to hundreds of images?

Images of Fixed Size

  • Open Inkscape and import a test raster image. It doesn’t matter what image you choose, as long as its dimensions match the dimensions of your target images.  Position the image on the page as you desire.
  • Save the image as drawing.svg.
  • In the directory where you saved your SVG, create a subdirectory and place all your target images there.
  • In the same subdirectory create a script called generate_pdf.sh:
#!/bin/bash

rm *.svg
rm *.pdf

DIR=`pwd`

for i in `find . -iname "*jpg" -o -iname "*png"`; do
  SVG_NAME=${i%%.jpg}.svg
  PDF_NAME=${i%%.jpg}.pdf
  IMG_NAME=${i#./}
  cp ../drawing.svg $SVG_NAME
  sed -i "s,IMAGE_NAME,$DIR/$IMG_NAME," $SVG_NAME

  inkscape --without-gui --export-pdf=$PDF_NAME $SVG_NAME
done
  • Run the script, and it will generate an SVG and a PDF file for each image.
  • Print all PDF files:
$ IFS=$'\n'; for i in `find . -iname "*pdf"`; do echo $i; lpr -P printer_name $i; done

You can find out the name of the printer by running this command:

$ lpstat -d -p

Images of Variable Size

The easiest way I found is to use ImageMagic.

$ convert -rotate "90>" -page Letter *.jpg test.pdf

Then open test.pdf and print all pages. Be sure to check each page before printing, since you may need to print a couple of images manually.

Blog at WordPress.com.

  • Follow Following
    • N1nja Hacks
    • Already have a WordPress.com account? Log in now.
    • N1nja Hacks
    • Customize
    • Follow Following
    • Sign up
    • Log in
    • Report this content
    • View site in Reader
    • Manage subscriptions
    • Collapse this bar