Link to home
Start Free TrialLog in
Avatar of holli
holli

asked on

Add image to pdf

greetings.

my current objective is to add a watermark image (with the text "COPY") into the background of existing pdf-files.

i managed to add an image to existing files using pdf::reuse but it ended up beeing on an new page.

i´d be glad if anyone could jog me into the right direction.

thanks in advance
holli
Avatar of winmeister
winmeister
Flag of Italy image

The only way to do it is with pdfmodify http://www.sanface.com/pdfmodify.html , but.... it is not free!
Avatar of holli
holli

ASKER

always be careful with statements that use "always" or "only"...
ASKER CERTIFIED SOLUTION
Avatar of winmeister
winmeister
Flag of Italy image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of holli

ASKER

i finally did it myself, after heavy ringtfm. since i have unlimited points i hand the points to you (winmeister).

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();

Avatar of holli

ASKER

who needs commercial tools?
Thank you. Good job.