Add a Header to Every Page in a PDF?

8,905

Solution 1

If you're comfortable with command line, you could use pdftk to do the job.

Here are the steps:

1) Generate a pdf with your header where you want it (bkg.pdf);
2) Use the following command to add the file from 1) as a watermark;

pdftk inputfile.pdf background bkg.pdf output outputfile.pdf

You could generate the header file with e.g. LaTeX, or with Word or other word processing tool, even TextEdit.app.

Edit: Depending on what the contents of your PDF are (e.g. a scanned document), you may prefer a foreground "watermark" to cover the images; in that case, you should replace 'background' by 'stamp' in the above command.

Beware that you might need some iterations to make sure that you have things properly aligned.

Alternative option: use LaTeX to generate the header an include all pages, but it's a bit more involved.

Solution 2

You can use the Watermark PDF documents action in Automator to add an image on every page of a PDF file. You can specify location, scale, rotation, and opacity.

Manually fixing the workflow for Mac OS X Lion

Set up the entire automator workflow as you would, but skip adding the watermark image (you can't). Save the workflow to a file. Right-click the workflow in Finder and select Show Package Contents and navigate into Contents. Open document.wflow in a text editor, e.g. TextMate.

The actual parameters and their values are stored in the ActionParameters dictionary. The relevant key is filenames. By default, it looks like this:

<key>ActionParameters</key>
<dict>
    <key>angle</key>
    <integer>0</integer>
    <key>fileNames</key>
    <array/>
    <key>onePDF</key>
    <false/>

Just edit the <array/> declaration and add all files as <string>s, like so:

<key>fileNames</key>
<array>
        <string>/Users/danielbeck/Desktop/test.png</string>
</array>

Save the file, and reopen the workflow in Automator. The image will be correctly listed, and you can fix its position and other properties, before you apply it.

Remember that the workflow does not replace the input file as many others do, the output is written to a temporary file. Use the Move Finder Items action afterwards.


Your printer might support a watermark feature via the print dialog. Check for a watermark option in the popup list of the detailed print dialog.

Share:
8,905
David
Author by

David

Updated on September 18, 2022

Comments

  • David
    David almost 2 years

    Is there a way to add a small header to every page in a PDF on OS X? For example, some option in Preview or something? Maybe even something in AppleScript, etc?

    I have a 200+ page PDF file and need to add a small name and account number at the top of every page, and it would be great to be able to do it in an automated way before (or during) printing.

  • HikeMike
    HikeMike over 12 years
    The Automator action appears to be broken in Lion. They receive an NSURL from the file dialog, and send the isAbsolutePath message, which is defined for NSString. A really stupid bug. See here. Sorry about that.
  • David
    David over 12 years
    It doesn't look like my printer has that option, but the Automator is definitely worth looking into. (I've never used it before.) Probably won't be able to get to it until tomorrow, so I'll let you know. Thanks!
  • David
    David over 12 years
    Just noticed your recent comment. That might stop it, but it's still worth trying. If I need to, I can probably grab a trial version of a .NET PDF library and develop something custom on my workstation at work. Either way, it'll be tomorrow.
  • HikeMike
    HikeMike over 12 years
    @David If you're not afraid of XML, I found out how to circumvent the issue.
  • David
    David over 12 years
    Just needed to install pdftk and this worked perfectly. I wonder what else I can script up with this toolkit, it'll probably come in handy in my development work from time to time as well. Thanks!
  • Karolos
    Karolos over 12 years
    @David: You're welcome. This toolkit is extremely powerful when using it inside a script. I use it daily for many tasks. Be sure to read the documentation.
  • Nabil
    Nabil over 10 years
    there's a typo in the actual command invocation, it's "pdfdk" rather than "pdftk"