Once upon a time I had the same problem, which I then put away for 'later', but your request made me look it up.
The method for it is actually quite simple, however due to the level of documentation for PDF::API2, nobody knows how :)
Let's start by creating the document, add an A4-page, create text and gfxhandlers and add a font:Then we'll make some Extended Graphics states...One for everything we want transparent, and one for the non-transparent states.my $pdf = PDF::API2->new( -file => "Test.pdf" ); my $page1 = $pdf->page; $page1->mediabox (210/mm, 297/mm); my $gfx = $page1->gfx; my $text = $page1->text; my %fonts = ( Helvetica => { Roman => $pdf->corefont( 'Helvetica', -encoding => 'latin1' ), } );
Suppose we now want to write some transparent text:my $EGTransparent = $pdf->egstate(); my $EGNormal = $pdf->egstate(); $EGTransparent->transparency(0.5); $EGNormal->transparency(0);
And add a transparent image to write transparent text over:$text->egstate($EGTransparent); $text->font($fonts{Helvetica}{Roman}, 16/pt); $text->translate(31/mm,250/mm); $text->text("This is a Test, just so you know", undef); $text->egstate($EGNormal);
And then add some non-transparent text, to show the difference:$gfx->egstate($EGTransparent); $gfx->image($pdf->image_tiff("Image.tif"), 1/mm, 148/mm, 137/mm, 137/m +m); $gfx->egstate($EGNormal);
And save our result...of course :)$text->translate(31/mm,200/mm); $text->text("This is a Test, just so you know", undef);
All done.$pdf->save;
In reply to Re: PDF::API2 and opacity
by Neighbour
in thread PDF::API2 and opacity
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |