Adding header or footer information to existing PDF

Recently we had to deal with PDF manipulation, respectively the need to add header information to an existing PDF file. First thing I tried was using LaTeX as outlined by Stefan Lagotzki [1]. But a solution to apply more easy was needed. Imagemagick\’s \”composite\” does now the job quite well. Multipage PDF files have first to be split up and then being treated with composite as outlined below:

$ pdftk A=multipage.pdf cat A1 output multipage.1.pdf
$ pdftk A=multipage.pdf cat A2 output multipage.2.pdf

The commandline below takes the singlepage PDF at a resolution of 300dpi and resizes it to a percentage and then glues it to the header page, which is of the size A4. Resizing ensures, that the header information is always visible above the included singlepage:

$ composite -density 300 multipage.1.pdf -resize 93% header.ps -compose bumpmap -gravity south out.pdf

The header page could look like shown below:

%!PS-Adobe-1.0
%%DocumentMedia: A4 595 842 0 () ()
%%Orientation: Portrait
%%Pages: (atend)
%%DocumentFonts: Times-Roman Helvetica
%%EndComments
%%EndProlog
%%Page: 1 1
50 760 moveto
/Courier findfont 14 scalefont setfont
(Add your text right here...) show
showpage
%%Trailer
%%Pages: 1

[1] http://www.lagotzki.de/pdftk/index.html#FAQ

Leave a Reply