Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Edit PDF Text

by avik (Novice)
on May 15, 2006 at 18:05 UTC ( [id://549558]=perlquestion: print w/replies, xml ) Need Help??

avik has asked for the wisdom of the Perl Monks concerning the following question:

Dear Perl Monks, Simple question: i need to replace all ocurrences of a word within a PDF file. Is there a simple way to do it using PDF::API2 or PDF::Reuse?.. Thanks, A.T.

Replies are listed 'Best First'.
Re: Edit PDF Text
by ghenry (Vicar) on May 16, 2006 at 16:18 UTC

    You can't with PDF::Reuse (AFAIK), but can with PDF::API2

    In the Generic Methods, are the examples:

    $pdf = PDF::API2->new(); ... print $pdf->stringify; $pdf = PDF::API2->new(); ... $pdf->saveas("our/new.pdf"); $pdf = PDF::API2->new(-file => 'our/new.pdf'); ... $pdf->save;
    You could maybe sprintf the above print and manipulate the scalar that way, but I would print it first to see what comes out, or maybe try openScalar
    open($fh,'our/stream.pdf') or die "$@"; @pdf = <$fh>; $pdf = PDF::API->openScalar(join('',@pdf)); ... $pdf->saveas('our/new.pdf');
    You really only need to somehow grab the text with either of above, and then see what you can do with it.

    HTH,
    Gavin.

    Walking the road to enlightenment... I found a penguin and a camel on the way.....
    Fancy a yourname@perl.me.uk? Just ask!!!
Re: Edit PDF Text
by jbullock35 (Hermit) on May 17, 2006 at 07:51 UTC
    It might be easiest to uncompress the PDF with pdftk and then just use perl for the substitution:
    pdftk old.pdf output new.pdf uncompress perl -pi -e 's/oldstring/newstring/g' new.pdf
    If you want to recompress the file,
    pdftk new.pdf output new_compress.pdf compress
      Thanks, I will take a look at this option!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://549558]
Approved by GrandFather
Front-paged by planetscape
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (5)
As of 2024-04-19 17:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found