Canvas
in
Main rendering interface
Currently , , and implement this interface.
Implementations should measure x and y increasing to the left and down, respectively, with the origin in the top left corner. Implementations are free to use a unit other than points for length, but I can't guarantee that the results will look any good.
Table of Contents
- __construct() : mixed
- add_info() : mixed
- Add meta information to the pdf
- add_link() : mixed
- Add a link to the pdf
- add_named_dest() : mixed
- Add a named destination (similar to <a name="foo">...</a> in html)
- arc() : mixed
- Add an arc to the PDF See {@link Style::munge_color()} for the format of the color array.
- circle() : mixed
- Draws a circle at $x,$y with radius $r
- clipping_end() : mixed
- Ends the last clipping shape
- clipping_rectangle() : mixed
- Starts a clipping rectangle at x1,y1 with width w and height h
- clipping_roundrectangle() : mixed
- Starts a rounded clipping rectangle at x1,y1 with width w and height h
- filled_rectangle() : mixed
- Draws a filled rectangle at x1,y1 with width w and height h
- get_dompdf() : Dompdf
- get_font_baseline() : float
- Calculates font baseline, in points
- get_font_height() : float
- Calculates font height, in points
- get_height() : float
- Return the image's height in pixels
- get_page_count() : int
- Returns the total number of pages
- get_page_number() : int
- Returns the current page number
- get_text_width() : float
- Calculates text size, in points
- get_width() : float
- Returns the PDF's width in points
- image() : mixed
- Add an image to the pdf.
- javascript() : void
- line() : mixed
- Draws a line from x1,y1 to x2,y2
- new_page() : mixed
- Starts a new page
- output() : string
- Returns the PDF as a string.
- page_text() : mixed
- Writes text at the specified x and y coordinates on every page
- polygon() : mixed
- Draws a polygon
- rectangle() : mixed
- Draws a rectangle at x1,y1 with width w and height h
- restore() : mixed
- Restore last state
- rotate() : mixed
- Rotate
- save() : mixed
- Save current state
- scale() : mixed
- Scale
- set_default_view() : void
- Sets the default view
- set_opacity() : mixed
- Sets the opacity
- set_page_count() : mixed
- Sets the total number of pages
- skew() : mixed
- Skew
- stream() : mixed
- Streams the PDF directly to the browser.
- text() : mixed
- Writes text at the specified x and y coordinates See {@link Style::munge_color()} for the format of the color array.
- transform() : mixed
- Transform
- translate() : mixed
- Translate
Methods
__construct()
public
__construct([mixed $paper = "letter" ][, mixed $orientation = "portrait" ], Dompdf $dompdf) : mixed
Parameters
- $paper : mixed = "letter"
- $orientation : mixed = "portrait"
- $dompdf : Dompdf
Return values
mixed —add_info()
Add meta information to the pdf
public
add_info(string $name, string $value) : mixed
Parameters
- $name : string
-
Label of the value (Creator, Producer, etc.)
- $value : string
-
The text to set
Return values
mixed —add_link()
Add a link to the pdf
public
add_link(string $url, float $x, float $y, float $width, float $height) : mixed
Parameters
- $url : string
-
The url to link to
- $x : float
-
The x position of the link
- $y : float
-
The y position of the link
- $width : float
-
The width of the link
- $height : float
-
The height of the link
Return values
mixed —add_named_dest()
Add a named destination (similar to <a name="foo">...</a> in html)
public
add_named_dest(string $anchorname) : mixed
Parameters
- $anchorname : string
-
The name of the named destination
Return values
mixed —arc()
Add an arc to the PDF See {@link Style::munge_color()} for the format of the color array.
public
arc(float $x, float $y, float $r1, float $r2, float $astart, float $aend, array<string|int, mixed> $color, float $width[, array<string|int, mixed> $style = [] ]) : mixed
Parameters
- $x : float
-
X coordinate of the arc
- $y : float
-
Y coordinate of the arc
- $r1 : float
-
Radius 1
- $r2 : float
-
Radius 2
- $astart : float
-
Start angle in degrees
- $aend : float
-
End angle in degrees
- $color : array<string|int, mixed>
-
Color
- $width : float
- $style : array<string|int, mixed> = []
Return values
mixed —circle()
Draws a circle at $x,$y with radius $r
public
circle(float $x, float $y, float $r, array<string|int, mixed> $color[, float $width = null ][, array<string|int, mixed> $style = null ][, bool $fill = false ]) : mixed
See for the format of the color array. See for a description of the $style parameter (aka dash)
Parameters
- $x : float
- $y : float
- $r : float
- $color : array<string|int, mixed>
- $width : float = null
- $style : array<string|int, mixed> = null
- $fill : bool = false
-
Fills the circle if true
Return values
mixed —clipping_end()
Ends the last clipping shape
public
clipping_end() : mixed
Return values
mixed —clipping_rectangle()
Starts a clipping rectangle at x1,y1 with width w and height h
public
clipping_rectangle(float $x1, float $y1, float $w, float $h) : mixed
Parameters
- $x1 : float
- $y1 : float
- $w : float
- $h : float
Return values
mixed —clipping_roundrectangle()
Starts a rounded clipping rectangle at x1,y1 with width w and height h
public
clipping_roundrectangle(float $x1, float $y1, float $w, float $h, float $tl, float $tr, float $br, float $bl) : mixed
Parameters
- $x1 : float
- $y1 : float
- $w : float
- $h : float
- $tl : float
- $tr : float
- $br : float
- $bl : float
Return values
mixed —filled_rectangle()
Draws a filled rectangle at x1,y1 with width w and height h
public
filled_rectangle(float $x1, float $y1, float $w, float $h, array<string|int, mixed> $color) : mixed
Parameters
- $x1 : float
- $y1 : float
- $w : float
- $h : float
- $color : array<string|int, mixed>
Return values
mixed —get_dompdf()
public
get_dompdf() : Dompdf
Return values
Dompdf —get_font_baseline()
Calculates font baseline, in points
public
get_font_baseline(string $font, float $size) : float
Parameters
- $font : string
- $size : float
Return values
float —get_font_height()
Calculates font height, in points
public
get_font_height(string $font, float $size) : float
Parameters
- $font : string
- $size : float
Return values
float —get_height()
Return the image's height in pixels
public
get_height() : float
Return values
float —get_page_count()
Returns the total number of pages
public
get_page_count() : int
Return values
int —get_page_number()
Returns the current page number
public
get_page_number() : int
Return values
int —get_text_width()
Calculates text size, in points
public
get_text_width(string $text, string $font, float $size[, float $word_spacing = 0.0 ][, float $char_spacing = 0.0 ]) : float
Parameters
- $text : string
-
the text to be sized
- $font : string
-
the desired font
- $size : float
-
the desired font size
- $word_spacing : float = 0.0
-
word spacing, if any
- $char_spacing : float = 0.0
Return values
float —get_width()
Returns the PDF's width in points
public
get_width() : float
Return values
float —image()
Add an image to the pdf.
public
image(string $img_url, float $x, float $y, int $w, int $h[, string $resolution = "normal" ]) : mixed
The image is placed at the specified x and y coordinates with the given width and height.
Parameters
- $img_url : string
-
the path to the image
- $x : float
-
x position
- $y : float
-
y position
- $w : int
-
width (in pixels)
- $h : int
-
height (in pixels)
- $resolution : string = "normal"
-
The resolution of the image
Return values
mixed —javascript()
public
javascript(string $script) : void
Parameters
- $script : string
Return values
void —line()
Draws a line from x1,y1 to x2,y2
public
line(float $x1, float $y1, float $x2, float $y2, array<string|int, mixed> $color, float $width[, array<string|int, mixed> $style = null ]) : mixed
See for the format of the color array. See for a description of the format of the $style parameter (aka dash).
Parameters
- $x1 : float
- $y1 : float
- $x2 : float
- $y2 : float
- $color : array<string|int, mixed>
- $width : float
- $style : array<string|int, mixed> = null
Return values
mixed —new_page()
Starts a new page
public
new_page() : mixed
Subsequent drawing operations will appear on the new page.
Return values
mixed —output()
Returns the PDF as a string.
public
output([array<string|int, mixed> $options = [] ]) : string
Parameters
- $options : array<string|int, mixed> = []
-
Associative array: 'compress' => 1 or 0 (default 1).
Return values
string —page_text()
Writes text at the specified x and y coordinates on every page
public
page_text(float $x, float $y, string $text, string $font, float $size[, array<string|int, mixed> $color = [0, 0, 0] ][, float $word_space = 0.0 ][, float $char_space = 0.0 ][, float $angle = 0.0 ]) : mixed
The strings '{PAGE_NUM}' and '{PAGE_COUNT}' are automatically replaced with their current values.
Parameters
- $x : float
- $y : float
- $text : string
-
the text to write
- $font : string
-
the font file to use
- $size : float
-
the font size, in points
- $color : array<string|int, mixed> = [0, 0, 0]
- $word_space : float = 0.0
-
word spacing adjustment
- $char_space : float = 0.0
-
char spacing adjustment
- $angle : float = 0.0
-
angle to write the text at, measured CW starting from the x-axis
Return values
mixed —polygon()
Draws a polygon
public
polygon(array<string|int, mixed> $points, array<string|int, mixed> $color[, float $width = null ][, array<string|int, mixed> $style = null ][, bool $fill = false ]) : mixed
The polygon is formed by joining all the points stored in the $points
array. $points has the following structure:
array(0 => x1,
1 => y1,
2 => x2,
3 => y2,
...
);
See for the format of the color array. See for a description of the $style parameter (aka dash)
Parameters
- $points : array<string|int, mixed>
- $color : array<string|int, mixed>
- $width : float = null
- $style : array<string|int, mixed> = null
- $fill : bool = false
-
Fills the polygon if true
Return values
mixed —rectangle()
Draws a rectangle at x1,y1 with width w and height h
public
rectangle(float $x1, float $y1, float $w, float $h, array<string|int, mixed> $color, float $width[, array<string|int, mixed> $style = null ]) : mixed
See for the format of the color array. See for a description of the $style parameter (aka dash)
Parameters
- $x1 : float
- $y1 : float
- $w : float
- $h : float
- $color : array<string|int, mixed>
- $width : float
- $style : array<string|int, mixed> = null
Return values
mixed —restore()
Restore last state
public
restore() : mixed
Return values
mixed —rotate()
Rotate
public
rotate(float $angle, float $x, float $y) : mixed
Parameters
- $angle : float
-
angle in degrees for counter-clockwise rotation
- $x : float
-
Origin abscissa
- $y : float
-
Origin ordinate
Return values
mixed —save()
Save current state
public
save() : mixed
Return values
mixed —scale()
Scale
public
scale(float $s_x, float $s_y, float $x, float $y) : mixed
Parameters
- $s_x : float
-
scaling factor for width as percent
- $s_y : float
-
scaling factor for height as percent
- $x : float
-
Origin abscissa
- $y : float
-
Origin ordinate
Return values
mixed —set_default_view()
Sets the default view
public
set_default_view(string $view[, array<string|int, mixed> $options = [] ]) : void
Parameters
- $view : string
-
'XYZ' left, top, zoom 'Fit' 'FitH' top 'FitV' left 'FitR' left,bottom,right 'FitB' 'FitBH' top 'FitBV' left
- $options : array<string|int, mixed> = []
Return values
void —set_opacity()
Sets the opacity
public
set_opacity(float $opacity[, string $mode = "Normal" ]) : mixed
Parameters
- $opacity : float
- $mode : string = "Normal"
Return values
mixed —set_page_count()
Sets the total number of pages
public
set_page_count(int $count) : mixed
Parameters
- $count : int
Return values
mixed —skew()
Skew
public
skew(float $angle_x, float $angle_y, float $x, float $y) : mixed
Parameters
- $angle_x : float
- $angle_y : float
- $x : float
-
Origin abscissa
- $y : float
-
Origin ordinate
Return values
mixed —stream()
Streams the PDF directly to the browser.
public
stream(string $filename[, array<string|int, mixed> $options = [] ]) : mixed
Parameters
- $filename : string
-
The filename to present to the browser.
- $options : array<string|int, mixed> = []
-
Associative array: 'compress' => 1 or 0 (default 1); 'Attachment' => 1 or 0 (default 1).
Return values
mixed —text()
Writes text at the specified x and y coordinates See {@link Style::munge_color()} for the format of the color array.
public
text(float $x, float $y, string $text, string $font, float $size[, array<string|int, mixed> $color = [0, 0, 0] ][, float $word_space = 0.0 ][, float $char_space = 0.0 ][, float $angle = 0.0 ]) : mixed
Parameters
- $x : float
- $y : float
- $text : string
-
the text to write
- $font : string
-
the font file to use
- $size : float
-
the font size, in points
- $color : array<string|int, mixed> = [0, 0, 0]
- $word_space : float = 0.0
-
word spacing adjustment
- $char_space : float = 0.0
-
char spacing adjustment
- $angle : float = 0.0
-
angle
Return values
mixed —transform()
Transform
public
transform( $a, $b, $c, $d, $e, $f) : mixed
Parameters
Return values
mixed —translate()
Translate
public
translate(float $t_x, float $t_y) : mixed
Parameters
- $t_x : float
-
movement to the right
- $t_y : float
-
movement to the bottom