Skip to content
Basic PDF content editing and rendering support, including text, images, fonts and general graphics
Perl 6
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
etc
lib/PDF
t
.gitignore
.travis.yml
Changes
LICENSE
META6.json
README.md
appveyor.yml

README.md

PDF::Content

This Perl 6 module is a library of roles and classes for basic PDF content creation and rendering, including text, images, fonts and general graphics.

It is centered around implementing a graphics state machine and provding support for the operators and graphics variables as listed in the PDF::API6 Graphics Documentation.

Key roles and classes:

PDF::Content

implements a PDF graphics state machine for composition, or rendering:

use PDF::Content;
my PDF::Content $gfx .= new;
$gfx.BeginText;
$gfx.Font = 'F1', 16;
$gfx.TextMove(10, 20);
$gfx.ShowText('Hello World');
$gfx.EndText;
say $gfx.Str;
# BT
#  /F1 16 Tf
#  10 20 Td
#  (Hello World) Tj
# ET

PDF::Content::Image

handles the loading of some common image formats

It currently supports: PNG, GIF and JPEG.

use PDF::Content::XObject;
my PDF::Content::XObject $image .= open: "t/images/lightbulb.gif";
say "image has size {$image.width} X {$image.height}";
say $image.data-uri;
# data:image/gif;base64,R0lGODlhEwATAMQA...

PDF::Content::Font::CoreFont

provides simple support for core fonts

use PDF::Content::Font::CoreFont;
my PDF::Content::Font::CoreFont $font .= load-font( :family<Times-Roman>, :weight<bold> );
say $font.encode("¶Hi");
say $font.stringwidth("RVX"); # 2166
say $font.stringwidth("RVX", :kern); # 2111

PDF::Content::Text::Block

a utility class for creating and outputting simple text lines and paragraphs:

use PDF::Content;
use PDF::Content::Font::CoreFont;
use PDF::Content::Text::Block;
my PDF::Content::Font::CoreFont $font .= load-font( :family<helvetica>, :weight<bold> );
my $font-size = 16;
my $text = "Hello.  Ting, ting-ting. Attention! … ATTENTION! ";
my PDF::Content::Text::Block $text-block .= new( :$text, :$font, :$font-size );
my PDF::Content $gfx .= new;
$gfx.BeginText;
$text-block.render($gfx);
$gfx.EndText;
say $gfx.Str;

PDF::Content::Color

Simple Color construction functions:

use PDF::Content;
use PDF::Content::Color :color, :ColorName;
PDF::Content $gfx .= new;
$gfx.FillColor = color Blue; # named color
$gfx.StrokeColor = color '#fa9'; # RGB mask, 3 digit
$gfx.StrokeColor = color '#ffaa99'; # RGB mask, 6 digit
$gfx.StrokeColor = color [1, .8, .1, .2]; # CMYK color values (0..1)
$gfx.StrokeColor = color [1, .5, .1];     # RGB color values (0..1)
$gfx.StrokeColor = color [255, 127, 25];  # RGB color values (0..255)
$gfx.StrokeColor = color .7; # Shade of gray
use Color;
my Color $red .= new(0xff, 0x0a, 0x0a)
$gfx.StrokeColor = color $red; # Color objects

See Also

  • PDF::Lite minimal creation and manipulation of PDF documents.

  • PDF::API6 PDF manipulation library.

You can’t perform that action at this time.