Content
[Raku PDF Project] / [PDF-Content Module] / PDF::Content
class PDF::Content
PDF Content construction and manipulation
Description
implements a PDF graphics state machine for composition, or rendering:
Synposis
use lib 't';
use PDF::Content;
use PDF::Content::Canvas;
use PDFTiny;
my PDFTiny $pdf .= new;
my PDF::Content::Canvas $canvas = $pdf.add-page;
my PDF::Content $gfx .= new: :$canvas;
$gfx.use-font: $pdf.core-font('Courier'); # define /F1 font
$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
# ETMethods
method graphics
method graphics(
&meth
) returns MuAdd a graphics block
method text
method text(
&meth
) returns MuAdd a text block
method mark
method mark(
Str $t,
&meth,
|c
) returns PDF::Content::TagAdd a marked content block
multi method tag
multi method tag(
Str $tag,
Bool :$mark,
*%props
) returns PDF::Content::TagAdd an empty content tag, optionally marked
multi method tag
multi method tag(
Str $tag,
&meth,
Bool :$mark,
*%props
) returns PDF::Content::TagAdd tagged content, optionally marked
method load-image
method load-image(
$spec
) returns PDF::Content::XObjectOpen an image from a file-spec or data-uri
method inline-images
method inline-images() returns Seqextract any inline images from the content stream. returns an array of XObject Images
method transform
method transform(
|c
) returns Muperform a series of graphics transforms
method text-transform
method text-transform(
|c
) returns Muperform a series of text transforms
multi method do
multi method do(
PDF::Content::XObject $obj,
List :$position where { ... } = Code.new,
Str :$align is copy where { ... } = "left",
Str :$valign is copy where { ... } = "bottom",
Numeric :$width is copy,
Numeric :$height is copy,
Bool :$inline = Bool::False
) returns Listplace an image, or form object
method use-pattern
method use-pattern(
Hash $pat where { ... }
) returns Muensure pattern is declared as a resource
multi method paint
multi method paint(
&meth,
*%o
) returns Mubuild a path, then fill and stroke it
multi sub make-font
multi sub make-font(
PDF::Content::Font:D(Any):D $dict
) returns PDF::COS::Dictassociate a font dictionary with a font object
method text-box
method text-box(
Any:D :$font where { ... } = Code.new,
Numeric:D :$font-size = Code.new,
*%opt
) returns PDF::Content::Text::Boxcreate a text box object for use in graphics .print() or .say() methods
method print
method print(
Str:D $text,
:$font! where { ... },
*%opt
) returns Listoutput text leave the text position at the end of the current line
method text-position
method text-position() returns PDF::Content::Vectorget or set the current text position
multi method print
multi method print(
PDF::Content::Text::Box $text-box,
List :$position where { ... },
Bool :$nl = Bool::False,
Bool :$preserve = Bool::True
) returns Listprint a text block object
method say
method say(
$text = "",
*%opt
) returns Muoutput text; move the text position down one line
multi method set-font
multi method set-font(
Hash $font,
Numeric $size = 16
) returns Muthin wrapper to $.op(SetFont, ...)
method font
method font() returns ArrayGet or set the current font as (font-size)
multi method print
multi method print(
Str $text,
:$font = Code.new,
|c
) returns Listprint text to the content stream
method html-canvas
method html-canvas(
&mark-up,
|c
) returns Muadd graphics using HTML Canvas 2D API
The HTML::Canvas::To::PDF Raku module must be installed to use this method
method draw
method draw(
$html-canvas,
:$renderer,
|c
) returns Murender an HTML canvas
method base-coords
method base-coords(
*@coords where { ... },
:$user = Bool::True,
:$text = Code.new
) returns Arraymap transformed user coordinates to untransformed (default) coordinates
method user-coords
method user-coords(
*@coords where { ... },
:$user = Bool::True,
:$text = Code.new
) returns Arrayinverse of base-coords