in reply to Re: PDF::API2 and opacity
in thread PDF::API2 and opacity

Neighbour, thanks for your code! It's close to what I'm searching and maybe this will help me to get to what I want to accomplish! But maybe you can help me directly, too:

I'm trying to import an existing PDF page from file into a new PDF that is just beeing created with PDF::API2. I need to set the attribute "overprint" so the text above is printed over the background (without this attribute/option, the background is not printed behind the text so some printers leave white lines when printing the black ink).

The module ExtGState, Extended Graphics states, seems to have methods for this attribute, but I don't know how to say they have to be applied to the background image. Any suggestions?

Replies are listed 'Best First'.
Re^3: PDF::API2 and opacity
by Neighbour (Friar) on Aug 03, 2010 at 14:14 UTC
    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);