Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
Problems? Is your data what you think it is?
 
PerlMonks  

Edit PDF Text

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

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.

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 12: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 03: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
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.