CPDF
in package
implements
Canvas
PDF rendering interface
Dompdf\Adapter\CPDF provides a simple stateless interface to the stateful one provided by the Cpdf class.
Unless otherwise mentioned, all dimensions are in points (1/72 in). The coordinate origin is in the top left corner, and y values increase downwards.
See for more complete documentation on the underlying class.
Interfaces, Classes and Traits
- Canvas
- Main rendering interface
Table of Contents
- $PAPER_SIZES : mixed
- Dimensions of paper sizes in points
- $_current_opacity : float
- Currently-applied opacity level (0 - 1)
- $_dompdf : Dompdf
- The Dompdf object
- $_height : mixed
- PDF height, in points
- $_image_cache : array<string|int, mixed>
- Array of temporary cached images to be deleted when processing is complete
- $_page_count : int
- Total number of pages
- $_page_number : int
- Current page number
- $_page_text : array<string|int, mixed>
- Text to display on every page
- $_pages : array<string|int, mixed>
- Array of pages for accessing after rendering is initially complete
- $_pdf : Cpdf
- Instance of Cpdf class
- $_width : float
- PDF width, in points
- __construct() : mixed
- Class constructor
- __destruct() : mixed
- Class destructor
- 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)
- add_object() : mixed
- Adds a specified 'object' to the document
- 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
- close_object() : mixed
- Closes the current 'object'
- filled_rectangle() : mixed
- Draws a filled rectangle at x1,y1 with width w and height h
- get_cpdf() : Cpdf
- Returns the Cpdf instance
- get_dompdf() : Dompdf
- get_font_baseline() : float
- Calculates font baseline, in points
- get_font_height() : float|int
- Calculates font height, in points
- get_height() : float
- Returns the PDF's height in points
- get_messages() : string
- Returns logging messages generated by the Cpdf class
- get_page_count() : int
- Returns the total number of pages in the document
- get_page_number() : int
- Returns the current page number
- get_text_width() : float|int
- Calculates text size, in points
- get_width() : float
- Returns the PDF's width in points
- image() : mixed
- Add an image to the pdf.
- input() : mixed
- javascript() : void
- line() : mixed
- Canvas implementation
- new_page() : int
- Starts a new page
- open_object() : int
- Opens a new 'object'
- output() : string
- Returns the PDF as a string.
- page_line() : mixed
- Draw line at the specified coordinates on every page.
- page_script() : mixed
- Processes a script on every page
- 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
- register_string_subset() : mixed
- reopen_object() : mixed
- Reopens an existing 'object'
- reopen_serialized_object() : mixed
- restore() : mixed
- Restore last state
- rotate() : mixed
- Rotate
- save() : mixed
- Save current state
- scale() : mixed
- Scale
- select() : mixed
- serialize_object() : mixed
- set_default_view() : void
- Sets the default view
- set_opacity() : mixed
- Sets the opacity
- set_page_count() : mixed
- Sets the page count
- set_page_number() : mixed
- Sets the current page number
- skew() : mixed
- Skew
- stop_object() : mixed
- Stops the specified 'object' from appearing in the document.
- stream() : mixed
- Streams the PDF to the client.
- text() : mixed
- Writes text at the specified x and y coordinates See {@link Style::munge_color()} for the format of the color array.
- textarea() : mixed
- transform() : mixed
- Transform
- translate() : mixed
- Translate
- _add_page_text() : mixed
- Add text to each page after rendering is complete
- _convert_gif_bmp_to_png() : string
- Convert a GIF or BMP image to a PNG image
- _set_fill_color() : mixed
- Sets the fill colour
- _set_fill_transparency() : mixed
- Sets fill transparency
- _set_line_style() : mixed
- Sets the line style
- _set_line_transparency() : mixed
- Sets line transparency
- _set_stroke_color() : mixed
- Sets the stroke color
- y() : float
- Remaps y coords from 4th to 1st quadrant
Properties
$PAPER_SIZES
Dimensions of paper sizes in points
public
static mixed
$PAPER_SIZES
= ["4a0" => [0, 0, 4767.87, 6740.79], "2a0" => [0, 0, 3370.39, 4767.87], "a0" => [0, 0, 2383.94, 3370.39], "a1" => [0, 0, 1683.78, 2383.94], "a2" => [0, 0, 1190.55, 1683.78], "a3" => [0, 0, 841.89, 1190.55], "a4" => [0, 0, 595.28, 841.89], "a5" => [0, 0, 419.53, 595.28], "a6" => [0, 0, 297.64, 419.53], "a7" => [0, 0, 209.76, 297.64], "a8" => [0, 0, 147.4, 209.76], "a9" => [0, 0, 104.88, 147.4], "a10" => [0, 0, 73.7, 104.88], "b0" => [0, 0, 2834.65, 4008.19], "b1" => [0, 0, 2004.09, 2834.65], "b2" => [0, 0, 1417.32, 2004.09], "b3" => [0, 0, 1000.63, 1417.32], "b4" => [0, 0, 708.66, 1000.63], "b5" => [0, 0, 498.9, 708.66], "b6" => [0, 0, 354.33, 498.9], "b7" => [0, 0, 249.45, 354.33], "b8" => [0, 0, 175.75, 249.45], "b9" => [0, 0, 124.72, 175.75], "b10" => [0, 0, 87.87, 124.72], "c0" => [0, 0, 2599.37, 3676.54], "c1" => [0, 0, 1836.85, 2599.37], "c2" => [0, 0, 1298.27, 1836.85], "c3" => [0, 0, 918.4299999999999, 1298.27], "c4" => [0, 0, 649.13, 918.4299999999999], "c5" => [0, 0, 459.21, 649.13], "c6" => [0, 0, 323.15, 459.21], "c7" => [0, 0, 229.61, 323.15], "c8" => [0, 0, 161.57, 229.61], "c9" => [0, 0, 113.39, 161.57], "c10" => [0, 0, 79.37, 113.39], "ra0" => [0, 0, 2437.8, 3458.27], "ra1" => [0, 0, 1729.13, 2437.8], "ra2" => [0, 0, 1218.9, 1729.13], "ra3" => [0, 0, 864.5700000000001, 1218.9], "ra4" => [0, 0, 609.45, 864.5700000000001], "sra0" => [0, 0, 2551.18, 3628.35], "sra1" => [0, 0, 1814.17, 2551.18], "sra2" => [0, 0, 1275.59, 1814.17], "sra3" => [0, 0, 907.09, 1275.59], "sra4" => [0, 0, 637.8, 907.09], "letter" => [0, 0, 612.0, 792.0], "half-letter" => [0, 0, 396.0, 612.0], "legal" => [0, 0, 612.0, 1008.0], "ledger" => [0, 0, 1224.0, 792.0], "tabloid" => [0, 0, 792.0, 1224.0], "executive" => [0, 0, 521.86, 756.0], "folio" => [0, 0, 612.0, 936.0], "commercial #10 envelope" => [0, 0, 684, 297], "catalog #10 1/2 envelope" => [0, 0, 648, 864], "8.5x11" => [0, 0, 612.0, 792.0], "8.5x14" => [0, 0, 612.0, 1008.0], "11x17" => [0, 0, 792.0, 1224.0]]
array;
$_current_opacity
Currently-applied opacity level (0 - 1)
protected
float
$_current_opacity
= 1
$_dompdf
The Dompdf object
protected
Dompdf
$_dompdf
$_height
PDF height, in points
protected
mixed
$_height
float;
$_image_cache
Array of temporary cached images to be deleted when processing is complete
protected
array<string|int, mixed>
$_image_cache
$_page_count
Total number of pages
protected
int
$_page_count
$_page_number
Current page number
protected
int
$_page_number
$_page_text
Text to display on every page
protected
array<string|int, mixed>
$_page_text
$_pages
Array of pages for accessing after rendering is initially complete
protected
array<string|int, mixed>
$_pages
$_pdf
Instance of Cpdf class
protected
Cpdf
$_pdf
$_width
PDF width, in points
protected
float
$_width
Methods
__construct()
Class constructor
public
__construct([mixed $paper = "letter" ][, string $orientation = "portrait" ], Dompdf $dompdf) : mixed
Parameters
- $paper : mixed = "letter"
-
- $orientation : string = "portrait"
-
The orientation of the document (either 'landscape' or 'portrait')
- $dompdf : Dompdf
-
The Dompdf instance
Return values
mixed —__destruct()
Class destructor
public
__destruct() : mixed
Deletes all temporary image files
Return values
mixed —add_info()
Add meta information to the PDF
public
add_info(string $label, string $value) : mixed
Parameters
- $label : 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 —add_object()
Adds a specified 'object' to the document
public
add_object(int $object[, string $where = 'all' ]) : mixed
$object int specifying an object created with . $where can be one of:
- 'add' add to current page only
- 'all' add to every page from the current one onwards
- 'odd' add to all odd numbered pages from now on
- 'even' add to all even numbered pages from now on
- 'next' add the object to the next page only
- 'nextodd' add to all odd numbered pages from the next one
- 'nexteven' add to all even numbered pages from the next one
Parameters
- $object : int
- $where : string = 'all'
Tags
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
- $y : float
- $r1 : float
- $r2 : float
- $astart : float
- $aend : float
- $color : array<string|int, mixed>
- $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 $r1, array<string|int, mixed> $color[, null $width = null ][, null $style = null ][, bool $fill = false ]) : mixed
Parameters
- $x : float
- $y : float
- $r1 : float
- $color : array<string|int, mixed>
- $width : null = null
- $style : null = null
- $fill : bool = false
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 $rTL, float $rTR, float $rBR, float $rBL) : mixed
Parameters
- $x1 : float
- $y1 : float
- $w : float
- $h : float
- $rTL : float
- $rTR : float
- $rBR : float
- $rBL : float
Return values
mixed —close_object()
Closes the current 'object'
public
close_object() : mixed
Tags
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_cpdf()
Returns the Cpdf instance
public
get_cpdf() : Cpdf
Return values
Cpdf —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|int
Parameters
- $font : string
- $size : float
Tags
Return values
float|int —get_height()
Returns the PDF's height in points
public
get_height() : float
Return values
float —get_messages()
Returns logging messages generated by the Cpdf class
public
get_messages() : string
Return values
string —get_page_count()
Returns the total number of pages in the document
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, int $word_spacing, int $char_spacing) : float|int
Parameters
- $text : string
- $font : string
- $size : float
- $word_spacing : int
- $char_spacing : int
Return values
float|int —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, float $x, float $y, int $w, int $h[, string $resolution = "normal" ]) : mixed
Parameters
- $img : string
- $x : float
- $y : float
- $w : int
- $h : int
- $resolution : string = "normal"
Return values
mixed —input()
public
input(mixed $x, mixed $y, mixed $w, mixed $h, mixed $type, mixed $font, mixed $size[, mixed $color = [0, 0, 0] ]) : mixed
Parameters
- $x : mixed
- $y : mixed
- $w : mixed
- $h : mixed
- $type : mixed
- $font : mixed
- $size : mixed
- $color : mixed = [0, 0, 0]
Return values
mixed —javascript()
public
javascript(string $code) : void
Parameters
- $code : string
Return values
void —line()
Canvas implementation
public
line(float $x1, float $y1, float $x2, float $y2, array<string|int, mixed> $color, float $width[, array<string|int, mixed> $style = [] ]) : mixed
Parameters
- $x1 : float
- $y1 : float
- $x2 : float
- $y2 : float
- $color : array<string|int, mixed>
- $width : float
- $style : array<string|int, mixed> = []
Return values
mixed —new_page()
Starts a new page
public
new_page() : int
Return values
int —open_object()
Opens a new 'object'
public
open_object() : int
While an object is open, all drawing actions are recorded in the object, as opposed to being drawn on the current page. Objects can be added later to a specific page or to several pages.
The return value is an integer ID for the new object.
Tags
Return values
int —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_line()
Draw line at the specified coordinates on every page.
public
page_line(float $x1, float $y1, float $x2, float $y2, array<string|int, mixed> $color, float $width[, array<string|int, mixed> $style = [] ]) : mixed
Parameters
- $x1 : float
- $y1 : float
- $x2 : float
- $y2 : float
- $color : array<string|int, mixed>
- $width : float
- $style : array<string|int, mixed> = []
-
optional
Return values
mixed —page_script()
Processes a script on every page
public
page_script(string $code[, string $type = "text/php" ]) : mixed
The variables $pdf, $PAGE_NUM, and $PAGE_COUNT are available.
This function can be used to add page numbers to all pages after the first one, for example.
Parameters
- $code : string
-
the script code
- $type : string = "text/php"
-
the language type for script
Return values
mixed —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[, null $width = null ][, array<string|int, mixed> $style = [] ][, bool $fill = false ]) : mixed
Parameters
- $points : array<string|int, mixed>
- $color : array<string|int, mixed>
- $width : null = null
- $style : array<string|int, mixed> = []
- $fill : bool = false
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 = [] ]) : mixed
Parameters
- $x1 : float
- $y1 : float
- $w : float
- $h : float
- $color : array<string|int, mixed>
- $width : float
- $style : array<string|int, mixed> = []
Return values
mixed —register_string_subset()
public
register_string_subset( $font, $string) : mixed
Parameters
Return values
mixed —reopen_object()
Reopens an existing 'object'
public
reopen_object(int $object) : mixed
Parameters
- $object : int
-
the ID of a previously opened object
Tags
Return values
mixed —reopen_serialized_object()
public
reopen_serialized_object(mixed $obj) : mixed
Parameters
- $obj : mixed
Tags
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
- $x : float
- $y : float
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
- $s_y : float
- $x : float
- $y : float
Return values
mixed —select()
public
select(mixed $x, mixed $y, mixed $w, mixed $h, mixed $font, mixed $size[, mixed $color = [0, 0, 0] ][, mixed $opts = [] ]) : mixed
Parameters
- $x : mixed
- $y : mixed
- $w : mixed
- $h : mixed
- $font : mixed
- $size : mixed
- $color : mixed = [0, 0, 0]
- $opts : mixed = []
Return values
mixed —serialize_object()
public
serialize_object(mixed $id) : mixed
Parameters
- $id : mixed
Tags
Return values
mixed —set_default_view()
Sets the default view
public
set_default_view(mixed $view[, mixed $options = [] ]) : void
Parameters
- $view : mixed
-
'XYZ' left, top, zoom 'Fit' 'FitH' top 'FitV' left 'FitR' left,bottom,right 'FitB' 'FitBH' top 'FitBV' left
- $options : 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 page count
public
set_page_count(int $count) : mixed
Parameters
- $count : int
Return values
mixed —set_page_number()
Sets the current page number
public
set_page_number(int $num) : mixed
Parameters
- $num : 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
- $y : float
Return values
mixed —stop_object()
Stops the specified 'object' from appearing in the document.
public
stop_object(int $object) : mixed
The object will stop being displayed on the page following the current one.
Parameters
- $object : int
Return values
mixed —stream()
Streams the PDF to the client.
public
stream([string $filename = "document.pdf" ][, array<string|int, mixed> $options = [] ]) : mixed
Parameters
- $filename : string = "document.pdf"
-
The filename to present to the client.
- $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
- $font : string
- $size : float
- $color : array<string|int, mixed> = [0, 0, 0]
- $word_space : float = 0.0
- $char_space : float = 0.0
- $angle : float = 0.0
Return values
mixed —textarea()
public
textarea(mixed $x, mixed $y, mixed $w, mixed $h, mixed $font, mixed $size[, mixed $color = [0, 0, 0] ]) : mixed
Parameters
- $x : mixed
- $y : mixed
- $w : mixed
- $h : mixed
- $font : mixed
- $size : mixed
- $color : mixed = [0, 0, 0]
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
- $t_y : float
Return values
mixed —_add_page_text()
Add text to each page after rendering is complete
protected
_add_page_text() : mixed
Return values
mixed —_convert_gif_bmp_to_png()
Convert a GIF or BMP image to a PNG image
protected
_convert_gif_bmp_to_png(string $image_url, int $type) : string
Parameters
- $image_url : string
- $type : int
Tags
Return values
string —The url of the newly converted image
_set_fill_color()
Sets the fill colour
protected
_set_fill_color(array<string|int, mixed> $color) : mixed
Parameters
- $color : array<string|int, mixed>
Return values
mixed —_set_fill_transparency()
Sets fill transparency
protected
_set_fill_transparency(string $mode, float $opacity) : mixed
Parameters
- $mode : string
-
the blending mode to use
- $opacity : float
-
0.0 fully transparent, 1.0 fully opaque
Tags
Return values
mixed —_set_line_style()
Sets the line style
protected
_set_line_style(float $width, string $cap, string $join, array<string|int, mixed> $dash) : mixed
Parameters
- $width : float
- $cap : string
- $join : string
- $dash : array<string|int, mixed>
Tags
Return values
mixed —_set_line_transparency()
Sets line transparency
protected
_set_line_transparency(string $mode, float $opacity) : mixed
Parameters
- $mode : string
-
the blending mode to use
- $opacity : float
-
0.0 fully transparent, 1.0 fully opaque
Tags
Return values
mixed —_set_stroke_color()
Sets the stroke color
protected
_set_stroke_color(array<string|int, mixed> $color) : mixed
Parameters
- $color : array<string|int, mixed>
Return values
mixed —y()
Remaps y coords from 4th to 1st quadrant
protected
y(float $y) : float
Parameters
- $y : float