#!/usr/bin/perl -w # # Example 12-5. Add a stamp to an existing document. # # Usage: perl example12-5.pl doodah.pdf # ########################################## # CAUTION: # The PDF document is modified IN-PLACE # Use only on a copies ########################################## use strict; use PDF::API2; # Used to generate the PDF output unless (defined($ARGV[0])) { die "Please provide a filename.\n"; } # Open the PDF file whose name was provided on the command line my $pdf = PDF::API2->open($ARGV[0]) or die "Couldn't open $ARGV[0]!\n"; # Initialize the font used to create the stamp my $font = $pdf->corefont('Helvetica'); my ($page, $text); # Loop through the pages for (my $n=1; $n <= $pdf->pages(); $n++) { $page = $pdf->openpage($n); # Create a new text block on the page, center and rotate it $text = $page->text(); $text->transform( -translate => [198, 306], -rotate => 45); # Set the font and fill color $text->font($font, 36); $text->fillcolor("#FF0000"); # Add a string of text to the text block $text->text_center('C O N F I D E N T I A L'); } # Update the original PDF file in-place $pdf->update(); $pdf->end; exit;