Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re^2: Add watermark to a pdf

by holli (Monsignor)
on Dec 28, 2004 at 17:58 UTC ( #417803=note: print w/ replies, xml ) Need Help??

in reply to Re: Add watermark to a pdf
in thread Add watermark to a pdf

thank you for that "form"-hint. that was what i needed. i finally assembled a script which does perfectly what i wanted to achieve:

i know that the string concatenation ($string) is a bit clumsy, but i wanted to add the comments. you cannot have comments in quotes, can you?

use strict; use PDF::API2; use PDF::Reuse; # specify files my $ifile = "c:/kopie/anlage-h-beg.pdf"; my $ofile = "c:/kopie/new.pdf"; #find out number of pages my $ipdf = PDF::API2->open($ifile); my $nop = $ipdf->pages; $ipdf->end(); #set outfile for PDF::Reuse prFile($ofile); #get font my $intName = prFont("Helvetica"); # assemble watermark text my $string = # save graphic state "q\n" . # Begin Text "BT\n" . # set font and "size" "/$intName 1 Tf\n" . # set a text matrix # 1. width of text # 2. rotation angle (counterclockwise) # 3. inclination (clockwise) # 4. height of text # 5. position x (0=left) # 6. position y (0=bottom) "180 60 -60 180 100 185 Tm\n" . #set rgb-color (values between 0 and 1) #"1 0 0 rg" . #set grayscale (white=1 black=0) "0.9 g\n" . # show text "(Kopie) Tj\n" . # End Text "ET\n" . "Q\n"; #loop over pages for (my $i=1;$i<=$nop;$i++) { #add watermark prAdd ($string); #add original content my $internalName = prForm ( { file => $ifile, page => $i, effect => 'print', tolerant => 'no' } ); #add pagebreak prPage; } #save and close prEnd();

Comment on Re^2: Add watermark to a pdf
Download Code
Re^3: Add watermark to a pdf
by Anonymous Monk on Jun 24, 2008 at 13:41 UTC
    but this only creates empty pages with my watermark....
Re^3: Add watermark to a pdf
by morryd (Initiate) on Jun 17, 2009 at 05:24 UTC
    To be a true watermark I would like the text to be on top but have an opacity value that would allow you to see the original document underneath. Does anyone know how to do this? Plus I would like to set the prMbox value based on the original pdf page
      I found an online pdf watermarking application. Hope it is helpful to a lot of people.
Re^3: Add watermark to a pdf
by Heffstar (Acolyte) on Mar 23, 2010 at 19:49 UTC

    This method of creating a watermark works well except that there are certain things that seem to screw up...

    Images currently inside document will be opaque and overtop of your watermark. Sometimes, the first page of a .pdf is totally blank, aside from the newly added watermark.

    Would anyone have a suggestion as to why this is?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://417803]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (15)
As of 2014-07-31 18:03 GMT
Find Nodes?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:

    Results (250 votes), past polls