Hildstrom Engineering Projects Publications Resume Links Contact About Pics Flickr Youtube

Bates Number a PDF (aka Bates Label a PDF)

bates-number-a-pdf.zip

I got a help call from my wife asking about adding Bates numbering (aka Bates labeling) to a PDF scan of a legal document. Bates numbering generally consists of a sequential 6+digit number that is stamped in the corner of documents. Many law firms prefix the Bates number with a letter or number code that corresponds to a particular case or client. So, the first document in my case may be 20 pages and Bates numbered HILD0000001 through HILD0000020. The second document in my case may be 5 pages and Bates labeled HILD0000021 through HILD0000025. This allows fine-grained tracking of every single page related to a case.

Wow, Bates numbering software is expensive. During my quick search I came across several shareware programs with 7-day trial periods and $200+ price tags. They may be full-featured, flexible, and convenient, but that is out of our price range at the moment. Fortunately, I have done a bunch of PDF automation with pdftk in the past.

The relevant pdftk operation is multistamp, which overlays a multi-page PDF on top of the input PDF. So, the first order of business was to create a Microsoft Word document with a Bates numbering template in the footer with a 7-digit leading-zero page number. After inserting the text and a simple page number field into the footer, I used Toggle Field Codes to edit the page number format. Toggle Field Codes in the footer and it shows this:
HILD {PAGE \# "0000000" \* MERGEFORMAT}
I created it with legal paper size, which also works great when the input PDF is letter paper size. I adjusted the margins and page layout so the Bates label was about 0.25" from the bottom and right side, which will be in the white margins of most documents and not on top of existing text. Next, I inserted a single page break, copied all, and pasted until the document was 500 pages of nothing but page breaks and automatically-incremented Bates label footer. I saved this document as numbering.doc. To create a multistamp PDF, I printed the Word document using PDFCreator and saved the resulting PDF as numbering.pdf.

Next, I tested pdftk and the multistamp PDF manually:
C:\> pdftk example.pdf multistamp numbering.pdf output example-bates.pdf
It works like a champ. The legal-size overlay gets scaled to other paper sizes, so it seems to work great for legal, letter, A4, and other odd sized input PDF documents. If the input PDF is only 20 pages, pdftk's multistamp operation only uses the first 20 pages of the overlay. The next order of business was to make it easier to use, so I borrowed some stuff from my VLC batch script and developed this drag-and-drop one called bates-number-a-pdf.bat:
@if %1 == "" goto end
@set pdftk=%~d0%~p0\pdftk.exe
@set multistamp=%~d0%~p0\numbering.pdf
@%~d1
@cd %~p1
@set output=%~d1%~p1%~n1-bates%~x1
%pdftk% %1 multistamp %multistamp% output %output%
:end
pause
I put bates-number-a-pdf.bat, pdftk.exe, numbering.doc, and numbering.pdf into a zip file: bates-number-a-pdf.zip. Just unzip it and it is ready to use.

After unzipping the .zip file, here are the usage steps:

Combine PDF

combine-pdf.zip

I got another call asking about quickly combining multiple PDFs into a single pdf. Luckily, PDFTK is great and it makes this operation easy. I created a simple helper batch file to enable drag and drop in Windows. I started with an existing batch file and modified it for these purposes.
@if %1 == "" goto end
@set pdftk=%~d0%~p0\pdftk.exe
@%~d1
@cd %~p1
@set output=%~d1%~p1combined.pdf
if not exist "%output%" (
"%pdftk%" %1 cat output "%output%"
)else (
"%pdftk%" "%output%" %1 cat output "%output%-2"
move "%output%-2" "%output%"
)
:end
pause

After unzipping the .zip file, here are the usage steps: