Saturday, 10 September 2011

LDS Hymns in PDF form for service programmes

When producing a printed order of service it is traditional as well as convenient to include hymns in the printed programme.

This requires a source of the typeset hymns to insert into the programme.

Unfortunately there is no simple and convenient online digital source of typeset hymns that I am aware of.

There is not even PDF format LDS Hymn Book - if there was I could render the PDF as a bitmap (or convert to postscript) and embed it in the programme.

The closest and most convenient source is the online hymn book at which is driven by flash.

Fortunately it allows printing of the hymns (most of them) - but don't use your web browsers print option, use the "Print Song" option within the hymn player.

The hymns can be printed, and if you have a PDF printer driver installed you can produce a PDF.

The typeset hymn is represented in the PDF as a set of tiled bitmaps.

The following bash script will take such a PDF, extract out the tiled bitmaps, assembled them into one large png with borders cropped.

This png is then suitable for including into service programmes.

I usually edit the png to bring the hymn number down to the same line as the title, and the tempo up to the same line as the title, and also to reduce the space required by the copyright notice at the bottom of the page - this brings the png to the aspect ratio of an A4 (or A5) page allowing it to show full size - and is a requirement if all of the horizontal lines on the stave are to print properly.

#! /bin/bash

# Author: Sam Liddicott - This is dedicated to the public domain
# Usage: hymn2png print-to-file.pdf
# and produces print-to-file.pdf-1.png, print-to-file.pdf-2.png
# Although this is a bash script I tried to write it in LISP style
# hence the use of eval. I try to avoid most of the sin of eval
# by using it only to call another function but I guess it still
# breaks on file names with spaces in

get_row() { # page row
  pnmcat -white -leftright <( pngtopnm "$datadir/p-$1_$2.png" ) \

                           <( pngtopnm "$datadir/p-$1_$(($2 + 1)).png" )

get_next_row() { # page row
  if test -r "$datadir/p-$1_$2.png"
  then echo "<( get_row $1 $2 )"
       get_next_row $1 $(($2 + 2))

get_page() { # page
  eval pnmcat -white -topbottom $( get_next_row $1 1 )

get_next_page() { # page
  if test -r "$datadir/p-$1_1.png"
  then get_page $1 | pnmcrop -white | pnmtopng > "$file-$1.png"
       get_next_page $(($1 + 1))

mkdir -p "$datadir"
trap "rm -fr $datadir" EXIT

pdftohtml "$file" "$datadir/p.html"
get_next_page 1

EDIT: I try some other google terms and discover here that there is a PDF of the Hymn Book and the Primary Song book

This hymn book is vector form and so should scale better.
I print-to-file the page I want, and then convert that page to svg using pdftosvg.
I then edit the svg in inkscape and clip to a smaller size, and save-as .eps
I then insert the eps into libreoffice/openoffice documents and it prints very fine indeed.

No comments:

Post a Comment