PDF-Cairo
view release on metacpan or search on metacpan
examples/frontpage.pl view on Meta::CPAN
$markup = clean_markup(slurp("data/layout2.txt"));
# reuse first layout, changing options
$layout->size($col2->size);
$layout->spacing(0);
$layout->justify(1);
$layout->alignment('center');
$layout->markup($markup);
$pdf->move($col2->x, $col2->y + $col2->height);
$layout->show;
$col2->shrink(top => $layout->ink->{height});
# draw some red lines under the last article
$pdf->move($col2->x, $col2->y + $col2->height - 1);
$pdf->save;
$pdf->rel_line($col2->width, 0);
$pdf->rel_move(0, -2);
$pdf->rel_line(-$col2->width, 0);
$pdf->linewidth(0.1);
$pdf->strokecolor('red');
$pdf->stroke;
$pdf->restore;
$col2->shrink(top => 6);
# reuse the layout again with different options
$markup = clean_markup(slurp("data/layout3.txt"));
$layout->size($col2->size);
$layout->spacing(3);
$layout->justify(0);
$layout->alignment('left');
$layout->markup($markup);
$pdf->move($col2->x, $col2->y + $col2->height);
$layout->show;
$col2->shrink(top => $layout->ink->{height});
# test mixing in text from a custom icon font, created with
# http://s3.amazonaws.com/dotclue.org/svg2ttf.txt
# using data from https://game-icons.net
# Note the use of a literal UTF8 "â" character.
my $size = 32;
my $icon_font = $pdf->loadfont("data/icons.ttf");
$pdf->setfont($h_font2, $size/2);
$pdf->move($col2->x, $col2->y + $col2->height - $size);
$pdf->print("Iâve got ");
$pdf->setfont($icon_font, $size);
$pdf->print("A");
$pdf->setfont($h_font2, $size/2);
$pdf->print(" for your ");
$pdf->setfont($icon_font, $size);
$pdf->print("B");
# put an SVG image in lower-right corner of col2
my $svg = PDF::Cairo->loadsvg("data/treasure-map.svg");
$pdf->place($svg, $col2->x + $col2->width, $col2->y,
scale => 0.1, align => 'right');
$pdf->write;
exit;
sub slurp {
do {local( @ARGV, $/ ) = $_[0]; <>}
}
# strip EOL but preserve paragraph separator, to reflow text
# correctly.
#
# Note: if you set a font size in a <span>, and have a newline at
# the end of the markup, the final line will be set with the line
# spacing of the Cairo font size that was current when you called
# show(). Best not to do that.
#
sub clean_markup {
my ($markup) = @_;
$markup =~ s/\n(?!\n)/ /g;
$markup =~ s/\n /\n/g;
$markup =~ s/^ *//;
chomp($markup);
return $markup;
}
( run in 1.132 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )