I'm not entirely sure I understand what your problem is, but here is some code I use to make a "Test"-copy of a given PDF:
sub PrintTextAngle { my ($texthandler, $x, $y, $rot, $text, $options) = @_; $texthandler->transform('-translate'=> [6/mm+$x/mm,10/mm+$y/mm], ' +-rotate'=>$rot); $texthandler->text($text, $options); } my $pdf_input = PDF::API2->open("$Filename"); foreach my $pagenr (1..$pdf_input->pages) { my $page = $pdf_input->openpage($pagenr); my $texthandler = $page->text; my $font = $pdf_input->corefont( 'Helvetica-Bold', -encode => ' +latin1' ); $texthandler->fillcolor('grey'); $texthandler->font($font, 256/pt); PrintTextAngle($texthandler, 50, 60, 45, "TEST"); $texthandler->font($font, 56/pt); PrintTextAngle($texthandler, 20, 10, 0, "Do not throw away!"); } $pdf_input->saveas("$Filename-TEST.pdf");
This leaves the background (the imported PDF contents) intact and prints the text over this background (Though not semi-transparent, which you might want).

If you still insist on toying with the overprint setting, use this:

my $EGOverprint = $pdf->egstate(); my $EGNormal = $pdf->egstate(); $EGOverprint->strokeoverprint(1); $EGNormal->strokeoverprint(0);
Before calling PrintTextAngle, set the Extended Graphics State using:
$text->egstate($EGOverprint);
Then print, and afterwards (if you want to print some more without using overprint) restore the Extended Graphics State with:
$text->egstate($EGNormal);

In reply to Re^3: PDF::API2 and opacity by Neighbour
in thread PDF::API2 and opacity by Anonymous Monk

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.