DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Add A Watermark To A Multi-page PDF (a-la Pragmatic Programmers)

03.16.2006
| 7754 views |
  • submit to reddit
        This adds a text watermark to every page of a PDF document, as used by Pragmatic Programmers. Nothing secret here, more of a way to excercise "human" DRM. Used as:

   perl makepdf.pl "John Doe"

use PDF::Reuse;
use PDF::Reuse::Util;
use strict;

my ($name) = @ARGV;

prFile('book_for_someone.pdf');

my $sourcePdf = 'pdf_that_your_designer_made.pdf';
my $greeting = "This book is personalized for " . $name;

my $left = 1;
while ($left) {
   prFont('HO');
   prAdd("0 0 0 rg\n0 g\nf\n");
   prText( 38, 800, $greeting);
   $left = prSinglePage($sourcePdf);   
} 

prEnd;