PDF::API2::Content - Methods for adding graphics and text to a PDF |
PDF::API2::Content - Methods for adding graphics and text to a PDF
# Start with a PDF page (new or opened) my $pdf = PDF::API2->new(); my $page = $pdf->page(); # Add a new content object my $content = $page->gfx(); my $content = $page->text(); # Then call the methods below add graphics and text to the page.
The methods in this section change the coordinate system for the current content object relative to the rest of the document.
If you call more than one of these methods, the PDF specification recommends calling them in the following order: translate, rotate, scale, skew. Each change builds on the last, and you can get unexpected results when calling them in a different order.
rotate($degrees)
Use a negative argument to rotate clockwise.
$sa
degrees (counter-clockwise) from
the x axis and $sb
degrees (clockwise) from the y axis.
transform(%options)
$content->transform( -translate => [$x, $y], -rotate => $degrees, -scale => [$sx, $sy], -skew => [$sa, $sb], )
Performs multiple coordinate transformations at once, in the order recommended by the PDF specification (translate, rotate, scale, then skew).
This is equivalent to making each transformation separately.
transform_rel(%options)
transform
, except that it adds
to the previously set values.
transform
method instead.
linewidth($width)
linecap($style)
linejoin($style)
miterlimit($ratio)
The $ratio
is the maximum length of the miter (inner to outer
corner) divided by the line width. Any miter above this ratio will be
converted to a bevel join. The practical effect is that lines meeting
at shallow angles are chopped off instead of producing long pointed
corners.
There is no documented default miter limit.
linedash()
linedash($length)
If called without any arguments, a solid line will be drawn.
If called with one argument, the dashes and gaps will have equal lengths.
If called with two or more arguments, the arguments represent alternating dash and gap lengths.
If called with a hash of arguments, a dash phase may be set, which specifies the distance into the pattern at which to start the dash.
flatness($tolerance)
egstate($object)
Note: The line will not appear until you call stroke
.
hline($x)
vline($y)
[$x1, $y1]
, and
then extends the path in lines along the specified coordinates.
($x, $y)
,
using the two specified points to create a cubic Bezier curve, and
updates the current position to be the new point.
Note: The curve will not appear until you call stroke
.
($x, $y)
,
using the two specified points to create a spline, and updates the
current position to be the new point.
Note: The curve will not appear until you call stroke
.
[x, y]
.
The major and minor axes of the ellipse are $a
and $b
,
respectively, and the arc moves from $alpha
degrees to $beta
degrees. The current position is then set to the endpoint of the arc.
Set $move
to a true value if this arc is the beginning of a new
path instead of the continuation of an existing path.
[x1, y1]
to [x2, y2]
. The current position is then set
to the endpoint of the arc.
Set $move
to a true value if this arc is the beginning of a new
path instead of the continuation of an existing path.
Set $outer
to a true value to draw the larger arc between the two
points instead of the smaller one.
Set $reverse
to a true value to draw the mirror image of the
specified arc.
$radius * 2
cannot be smaller than the distance from [x1, y1]
to
[x2, y2]
.
Note: The curve will not appear until you call stroke
.
[$x, $y]
, with major and
minor axes specified by $a
and $b
, respectively.
Note: The ellipse will not appear until you call stroke
or fill
.
[$x, $y]
with the specified
radius.
Note: The circle will not appear until you call stroke
or fill
.
[$x, $y]
.
The major and minor axes of the ellipse are $a
and $b
,
respectively, and the arc moves from $alpha
degrees to $beta
degrees.
Note: The pie will not appear until you call stroke
or fill
.
[$x, $y]
and with the specified widths and heights.
Note: The rectangle will not appear until you call stroke
or fill
.
[$x1, $y1]
and and [$x2, $y2]
specifying opposite corners.
Note: The rectangle will not appear until you call stroke
or fill
.
fill($use_even_odd_fill)
If the path intersects with itself, the nonzero winding rule will be used to determine which part of the path is filled in. If you would prefer to use the even-odd rule, pass a true argument.
See the PDF Specification, section 8.5.3.3, for more details on filling.
fillstroke($use_even_odd_fill)
clip($use_even_odd_fill)
fillcolor($color)
strokecolor($color)
# Use a named color $content->fillcolor('blue');
# Use an RGB color (start with '#') $content->fillcolor('#FF0000');
# Use a CMYK color (start with '%') $content->fillcolor('%FF000000');
RGB and CMYK colors can have one-byte, two-byte, three-byte, or
four-byte values for each color. For instance, cyan can be given as
%F000
or %FFFF000000000000
.
# Example my $image_object = $pdf->image_jpeg($my_image_file); $content->image($image_object, 100, 200);
Places an image on the page in the specified location.
If coordinate transformations have been made (see Coordinate
Transformations above), the position and scale will be relative to the
updated coordinates. Otherwise, [0,0] will represent the bottom left
corner of the page, and $width
and $height
will be measured at
72dpi.
For example, if you have a 600x600 image that you would like to be shown at 600dpi (i.e. one inch square), set the width and height to 72.
All of the following parameters that take a size are applied before any scaling takes place, so you don't need to adjust values to counteract scaling.
charspace($spacing)
wordspace($spacing)
hscale($scale)
lead($leading)
render($mode)
rise($distance)
Use this for creating superscripts or subscripts (usually with an adjustment to the font size as well).
This can also be used without arguments to retrieve the current text state settings.
Note: This does not currently work with the save
and restore
commands.
# Example my $pdf = PDF::API2->new(); my $font = $pdf->corefont('Helvetica'); $content->font($font, 12);
Sets the font and font size.
Note: There is a very good chance that these commands will be replaced in a future release.
cr()
cr($vertical_offset)
An offset can be passed as an argument to override the leading value. A positive offset will move the cursor up, and a negative offset will move the cursor down.
Pass zero as the argument to ignore the leading and get just a carriage return.
nl()
textpos()
Note: This does not affect the PDF in any way.
Options:
$distance
is the number of units beneath the
baseline, and $thickness
is the width of the line.
Multiple underlines can be made by passing several distances and thicknesses.
text_center($text)
text
, but centered on the current point.
text
, but right-aligned to the current point.
text
method
instead.
PDF::API2::Content - Methods for adding graphics and text to a PDF |