File: 060_transparency

package info (click to toggle)
libpdf-builder-perl 3.027-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 23,992 kB
  • sloc: perl: 107,532; makefile: 10
file content (59 lines) | stat: -rw-r--r-- 1,488 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/perl

# show writing opaque and translucent text by two methods

use strict;
use warnings;

use lib '../lib/';
use PDF::Builder;
use PDF::Builder::Util;
use POSIX;

my $compress = 'none'; # uncompressed streams
#my $compress = 'flate'; # compressed streams

my $pdf = PDF::Builder->new(-compress => $compress);
$pdf->mediabox(595,842);

my $TRANSPARENT = $pdf->egstate(); # Called just once
$TRANSPARENT->transparency(0.4);  # only 60% opaqueness

my $fnt = $pdf->corefont('Verdana-Bold');

my $page = $pdf->page();
my $text = $page->text();

# page 1: opaque red text put down, then almost transparent black partly over.
# both texts bleed off right side of page
$text->textlabel(30,750, $fnt,100, '100% Opaque', -color=>'#F00');

$text->egstate($TRANSPARENT);
$text->textlabel(30,720, $fnt,100, '40% Transparent', -color=>'#000');

# page 2: similar to page 1, but using different methods. bleed off left side.
$page = $pdf->page();
$text = $page->text();

$text->font($fnt, 100);
$text->fillcolor('red');
$text->translate(570,750);
$text->text_right('Opaque 100%');
$text->textend(); # back into graphics state so can do transparency

#$text->save();  # unnecessary, as this is the last segment
$text->egstate($TRANSPARENT);
$text->textstart(); # back into text mode
$text->font($fnt, 100);
$text->fillcolor('black');
$text->translate(570,720);
$text->text_right('Transparent 40%');
$text->textend();
#$text->restore();

$pdf->saveas("$0.pdf");
$pdf->end();

exit;

__END__