The PDF contains various checksums that make it difficult to replace text this way, unless you use code that recomputes the checksum and puts them into the PDF. It also positions the text based on the width, so you might have best luck with center justified text, for example.

In general, it is also possible that the PDF contains compressed text.

You also forgot binmode on the OUT file handle.

The crude way to do what you want is to convert the PDF to Postscript, substitute the text, and convert it back. I use the ImageMagick program 'convert' to do this.

`convert Build3.pdf Build3.ps` ... Postscript filtering code goes here ... `convert Build3.ps out.pdf`
There are also perl modules available to wrap the ImageMagick functionality. I believe that ImageMagick is in turn calling Ghostscript to handle the conversion, so you could use that directly, instead.

It should work perfectly the first time! - toma

In reply to Re: Editing/Replacing Text in a PDF by toma
in thread Editing/Replacing Text in a PDF by ikkon

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.