NAME
PDF::Make::Canvas - PDF content stream builder
SYNOPSIS
use PDF::Make::Canvas qw(:all);
my $canvas = PDF::Make::Canvas->new;
# Draw a rectangle
$canvas->q # save state
->w(2) # 2pt line width
->RG(1, 0, 0) # red stroke
->rg(1, 1, 0) # yellow fill
->re(100, 100, 200, 150) # rectangle
->B # fill and stroke
->Q; # restore state
# Draw text
$canvas->BT # begin text
->Tf('F1', 24) # set font
->Td(100, 700) # position
->Tj('Hello, PDF!') # show text
->ET; # end text
# Get the content stream bytes
my $bytes = $canvas->to_bytes;
DESCRIPTION
PDF::Make::Canvas builds PDF content streams using a fluent interface that mirrors the PDF operators. Each method returns $self for chaining.
CONSTRUCTOR
new
my $canvas = PDF::Make::Canvas->new;
Create a new empty canvas.
GRAPHICS STATE OPERATORS
q
$canvas->q;
Save the current graphics state.
Q
$canvas->Q;
Restore the previously saved graphics state.
cm
$canvas->cm($a, $b, $c, $d, $e, $f);
Modify the current transformation matrix by concatenating the specified matrix. The six values form a 3x3 transformation matrix.
w
$canvas->w($width);
Set the line width.
J
$canvas->J($cap);
Set the line cap style. Use the CAP_* constants.
j
$canvas->j($join);
Set the line join style. Use the JOIN_* constants.
M
$canvas->M($miter);
Set the miter limit.
d
$canvas->d(\@array, $phase);
Set the dash pattern. @array contains dash lengths, $phase is the starting offset.
ri
$canvas->ri($intent);
Set the rendering intent name.
i
$canvas->i($flatness);
Set the flatness tolerance.
gs
$canvas->gs($name);
Set the graphics state from a named resource.
PATH CONSTRUCTION OPERATORS
m
$canvas->m($x, $y);
Begin a new subpath at the given coordinates.
l
$canvas->l($x, $y);
Append a line from the current point to the given coordinates.
c
$canvas->c($x1, $y1, $x2, $y2, $x3, $y3);
Append a cubic Bézier curve with control points (x1,y1), (x2,y2) and endpoint (x3,y3).
v
$canvas->v($x2, $y2, $x3, $y3);
Append a cubic Bézier curve with the first control point at the current point.
y
$canvas->y($x1, $y1, $x3, $y3);
Append a cubic Bézier curve with the second control point at the endpoint.
re
$canvas->re($x, $y, $width, $height);
Append a rectangle.
h
$canvas->h;
Close the current subpath.
PATH PAINTING OPERATORS
S
$canvas->S;
Stroke the path.
s
$canvas->s;
Close and stroke the path.
f
$canvas->f;
Fill the path using the non-zero winding rule.
f_star
$canvas->f_star;
Fill the path using the even-odd rule.
B
$canvas->B;
Fill and stroke the path (non-zero winding).
B_star
$canvas->B_star;
Fill and stroke the path (even-odd).
b
$canvas->b;
Close, fill, and stroke the path (non-zero winding).
b_star
$canvas->b_star;
Close, fill, and stroke the path (even-odd).
n
$canvas->n;
End the path without filling or stroking.
CLIPPING OPERATORS
W
$canvas->W;
Modify the clipping path using non-zero winding rule.
W_star
$canvas->W_star;
Modify the clipping path using even-odd rule.
COLOR OPERATORS
CS, cs
$canvas->CS($name); # stroke color space
$canvas->cs($name); # fill color space
Set the color space.
G, g
$canvas->G($gray); # stroke gray
$canvas->g($gray); # fill gray
Set grayscale color (0=black, 1=white).
RG, rg
$canvas->RG($r, $g, $b); # stroke RGB
$canvas->rg($r, $g, $b); # fill RGB
Set RGB color (each component 0-1).
K, k
$canvas->K($c, $m, $y, $k); # stroke CMYK
$canvas->k($c, $m, $y, $k); # fill CMYK
Set CMYK color (each component 0-1).
TEXT OPERATORS
BT, ET
$canvas->BT; # begin text object
$canvas->ET; # end text object
Begin and end a text object.
Tc
$canvas->Tc($char_space);
Set character spacing.
Tw
$canvas->Tw($word_space);
Set word spacing.
Tz
$canvas->Tz($scale);
Set horizontal scaling (percentage).
TL
$canvas->TL($leading);
Set leading (line spacing).
Tf
$canvas->Tf($font, $size);
Set the font and size.
Tr
$canvas->Tr($mode);
Set the text rendering mode. Use the RENDER_* constants.
Ts
$canvas->Ts($rise);
Set text rise (baseline offset).
Td, TD
$canvas->Td($tx, $ty); # move text position
$canvas->TD($tx, $ty); # move and set leading
Move the text position.
Tm
$canvas->Tm($a, $b, $c, $d, $e, $f);
Set the text matrix.
T_star
$canvas->T_star;
Move to the start of the next line.
Tj
$canvas->Tj($text);
Show text.
TJ
$canvas->TJ(\@array);
Show text with positioning adjustments.
quote
$canvas->quote($text);
Move to next line and show text.
dquote
$canvas->dquote($aw, $ac, $text);
Set word and character spacing, then show text.
XOBJECT OPERATORS
Do
$canvas->Do($name);
Paint the named XObject.
UTILITY METHODS
to_bytes
my $bytes = $canvas->to_bytes;
Return the accumulated content stream as bytes.
len
my $length = $canvas->len;
Return the current byte length of the content.
clear
$canvas->clear;
Clear the content buffer for reuse.
CONSTANTS
Line Cap Styles
CAP_BUTT- Butt cap (default)CAP_ROUND- Round capCAP_SQUARE- Square cap
Line Join Styles
JOIN_MITER- Miter join (default)JOIN_ROUND- Round joinJOIN_BEVEL- Bevel join
Text Rendering Modes
RENDER_FILL- Fill text (default)RENDER_STROKE- Stroke textRENDER_FILL_STROKE- Fill then strokeRENDER_INVISIBLE- Invisible textRENDER_FILL_CLIP- Fill and add to clipping pathRENDER_STROKE_CLIP- Stroke and add to clipping pathRENDER_FILL_STROKE_CLIP- Fill, stroke, and clipRENDER_CLIP- Add to clipping path only
SEE ALSO
PDF::Make::Page, PDF::Make::Document
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 278:
Non-ASCII character seen before =encoding in 'Bézier'. Assuming UTF-8