PDFLib
in package
implements
Canvas
PDF rendering interface
Dompdf\Adapter\PDFLib provides a simple, stateless interface to the one provided by PDFLib.
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 PDFlib functions.
Interfaces, Classes and Traits
- Canvas
- Main rendering interface
Table of Contents
- $IN_MEMORY : bool
- Whether to create PDFs in memory or on disk
- $nativeFontsTpPDFLib : array<string|int, mixed>
- Transforms the list of native fonts into PDFLib compatible names (casesensitive)
- $PAPER_SIZES : mixed
- Dimensions of paper sizes in points
- $_current_opacity : array<string|int, mixed>
- The current opacity level
- $_dompdf : Dompdf
- $_file : string
- Name of temporary file used for PDFs created on disk
- $_fonts : array<string|int, mixed>
- Cache of font handles
- $_fontsFiles : array<string|int, mixed>
- Cache of fontFile checks
- $_gstates : array<string|int, mixed>
- List of gstate objects created for this PDF (for reuse)
- $_height : float
- PDF height, in points
- $_imgs : array<string|int, mixed>
- Cache of image handles
- $_last_fill_color : array<string|int, mixed>
- Last fill color used
- $_last_stroke_color : array<string|int, mixed>
- Last stroke color used
- $_objs : array<string|int, mixed>
- List of objects (templates) to add to multiple pages
- $_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 accesing after rendering is initially complete
- $_pdf : PDFLib
- Instance of PDFLib class
- $_width : float
- PDF width, in points
- $MAJOR_VERSION : null|int
- Saves the major version of PDFLib for compatibility requests
- __construct() : mixed
- Class constructor
- _set_fill_opacity() : mixed
- Sets the fill opacity
- _set_gstate() : int
- Sets the gstate
- _set_stroke_opacity() : mixed
- Sets the stroke opacity
- 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 the 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
- Close the current template
- 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|mixed
- 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_pdflib() : PDFLib
- Returns the PDFLib instance
- get_text_width() : mixed
- Calculates text size, in points
- get_width() : float|mixed
- 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
- open_object() : int
- Opens a new 'object' (template in PDFLib-speak)
- 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
- reopen_object() : void
- Reopen an existing object (NOT IMPLEMENTED) PDFLib does not seem to support reopening templates.
- 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
- set_page_number() : mixed
- skew() : mixed
- Skew
- stop_object() : mixed
- Stops the specified template 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.
- transform() : mixed
- Transform
- translate() : mixed
- Translate
- _add_page_text() : mixed
- Add text to each page after rendering is complete
- _close() : mixed
- Close the pdf
- _load_font() : int
- Loads a specific font and stores the corresponding descriptor.
- _place_objects() : mixed
- Add all active objects to the current page
- _set_fill_color() : mixed
- Sets the fill color
- _set_line_style() : void
- Sets the line style
- _set_stroke_color() : mixed
- Sets the line color
- getPDFLibMajorVersion() : int
- getPDFLibParameter() : mixed
- getPDFLibValue() : mixed
- setPDFLibParameter() : mixed
- setPDFLibValue() : mixed
- y() : float
- Remaps y coords from 4th to 1st quadrant
Properties
$IN_MEMORY
Whether to create PDFs in memory or on disk
public
static bool
$IN_MEMORY
= true
$nativeFontsTpPDFLib
Transforms the list of native fonts into PDFLib compatible names (casesensitive)
public
static array<string|int, mixed>
$nativeFontsTpPDFLib
= ["courier" => "Courier", "courier-bold" => "Courier-Bold", "courier-oblique" => "Courier-Oblique", "courier-boldoblique" => "Courier-BoldOblique", "helvetica" => "Helvetica", "helvetica-bold" => "Helvetica-Bold", "helvetica-oblique" => "Helvetica-Oblique", "helvetica-boldoblique" => "Helvetica-BoldOblique", "times" => "Times-Roman", "times-roman" => "Times-Roman", "times-bold" => "Times-Bold", "times-italic" => "Times-Italic", "times-bolditalic" => "Times-BoldItalic", "symbol" => "Symbol", "zapfdinbats" => "ZapfDingbats", "zapfdingbats" => "ZapfDingbats"]
$PAPER_SIZES
Dimensions of paper sizes in points
public
static mixed
$PAPER_SIZES
= []
array;
$_current_opacity
The current opacity level
protected
array<string|int, mixed>
$_current_opacity
$_dompdf
protected
Dompdf
$_dompdf
$_file
Name of temporary file used for PDFs created on disk
protected
string
$_file
$_fonts
Cache of font handles
protected
array<string|int, mixed>
$_fonts
$_fontsFiles
Cache of fontFile checks
protected
array<string|int, mixed>
$_fontsFiles
$_gstates
List of gstate objects created for this PDF (for reuse)
protected
array<string|int, mixed>
$_gstates
= []
$_height
PDF height, in points
protected
float
$_height
$_imgs
Cache of image handles
protected
array<string|int, mixed>
$_imgs
$_last_fill_color
Last fill color used
protected
array<string|int, mixed>
$_last_fill_color
$_last_stroke_color
Last stroke color used
protected
array<string|int, mixed>
$_last_stroke_color
$_objs
List of objects (templates) to add to multiple pages
protected
array<string|int, mixed>
$_objs
$_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 accesing after rendering is initially complete
protected
array<string|int, mixed>
$_pages
$_pdf
Instance of PDFLib class
protected
PDFLib
$_pdf
$_width
PDF width, in points
protected
float
$_width
$MAJOR_VERSION
Saves the major version of PDFLib for compatibility requests
protected
static null|int
$MAJOR_VERSION
= null
Methods
__construct()
Class constructor
public
__construct([string|array<string|int, mixed> $paper = "letter" ][, string $orientation = "portrait" ], Dompdf $dompdf) : mixed
Parameters
- $paper : string|array<string|int, mixed> = "letter"
-
The size of paper to use either a string (see ) or an array(xmin,ymin,xmax,ymax)
- $orientation : string = "portrait"
-
The orientation of the document (either 'landscape' or 'portrait')
- $dompdf : Dompdf
Return values
mixed —_set_fill_opacity()
Sets the fill opacity
public
_set_fill_opacity( $opacity[, $mode = "Normal" ]) : mixed
Parameters
Return values
mixed —_set_gstate()
Sets the gstate
public
_set_gstate( $gstate_options) : int
Parameters
Return values
int —_set_stroke_opacity()
Sets the stroke opacity
public
_set_stroke_opacity( $opacity[, $mode = "Normal" ]) : mixed
Parameters
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, Producter, 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 the specified object to the document
public
add_object(int $object[, string $where = 'all' ]) : mixed
$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
-
the object handle returned by open_object()
- $where : string = 'all'
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 $x1, float $y1, float $r1, float $r2, float $astart, float $aend, array<string|int, mixed> $color, float $width[, array<string|int, mixed> $style = [] ]) : mixed
Parameters
- $x1 : float
- $y1 : 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 $r, array<string|int, mixed> $color[, null $width = null ][, null $style = null ][, bool $fill = false ]) : mixed
Parameters
- $x : float
- $y : float
- $r : 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()
Close the current template
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_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|mixed
Return values
float|mixed —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_pdflib()
Returns the PDFLib instance
public
get_pdflib() : PDFLib
Return values
PDFLib —get_text_width()
Calculates text size, in points
public
get_text_width(string $text, string $font, float $size, int $word_spacing, int $letter_spacing) : mixed
Parameters
- $text : string
- $font : string
- $size : float
- $word_spacing : int
- $letter_spacing : int
Return values
mixed —get_width()
Returns the PDF's width in points
public
get_width() : float|mixed
Return values
float|mixed —image()
Add an image to the pdf.
public
image(string $img_url, float $x, float $y, int $w, int $h[, string $resolution = "normal" ]) : mixed
Parameters
- $img_url : string
- $x : float
- $y : float
- $w : int
- $h : int
- $resolution : string = "normal"
Return values
mixed —javascript()
public
javascript(string $code) : void
Parameters
- $code : 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
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
Return values
mixed —open_object()
Opens a new 'object' (template in PDFLib-speak)
public
open_object() : int
While an object is open, all drawing actions are recorded to the object instead of 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 ][, null $style = null ][, bool $fill = false ]) : mixed
Parameters
- $points : array<string|int, mixed>
- $color : array<string|int, mixed>
- $width : null = null
- $style : null = null
- $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[, null $style = null ]) : mixed
Parameters
- $x1 : float
- $y1 : float
- $w : float
- $h : float
- $color : array<string|int, mixed>
- $width : float
- $style : null = null
Return values
mixed —reopen_object()
Reopen an existing object (NOT IMPLEMENTED) PDFLib does not seem to support reopening templates.
public
reopen_object(int $object) : void
Parameters
- $object : int
-
the ID of a previously opened object
Tags
Return values
void —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 —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 total number of pages
public
set_page_count(int $count) : mixed
Parameters
- $count : int
Return values
mixed —set_page_number()
public
set_page_number( $num) : mixed
Parameters
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 template 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).
Tags
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] ], int $word_spacing, int $char_spacing, int $angle) : mixed
Parameters
- $x : float
- $y : float
- $text : string
- $font : string
- $size : float
- $color : array<string|int, mixed> = [0, 0, 0]
- $word_spacing : int
- $char_spacing : int
- $angle : int
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 —_close()
Close the pdf
protected
_close() : mixed
Return values
mixed —_load_font()
Loads a specific font and stores the corresponding descriptor.
protected
_load_font(string $font[, string $encoding = null ][, string $options = "" ]) : int
Parameters
- $font : string
- $encoding : string = null
- $options : string = ""
Return values
int —the font descriptor for the font
_place_objects()
Add all active objects to the current page
protected
_place_objects() : mixed
Return values
mixed —_set_fill_color()
Sets the fill color
protected
_set_fill_color(array<string|int, mixed> $color) : mixed
Parameters
- $color : array<string|int, mixed>
-
array(r,g,b)
Return values
mixed —_set_line_style()
Sets the line style
protected
_set_line_style(float $width, $cap, string $join, array<string|int, mixed> $dash) : void
Parameters
Return values
void —_set_stroke_color()
Sets the line color
protected
_set_stroke_color(array<string|int, mixed> $color) : mixed
Parameters
- $color : array<string|int, mixed>
-
array(r,g,b)
Return values
mixed —getPDFLibMajorVersion()
protected
getPDFLibMajorVersion() : int
Return values
int —getPDFLibParameter()
protected
getPDFLibParameter(string $keyword[, string $optlist = "" ]) : mixed
Parameters
- $keyword : string
- $optlist : string = ""
Return values
mixed —getPDFLibValue()
protected
getPDFLibValue(string $keyword[, string $optlist = "" ]) : mixed
Parameters
- $keyword : string
- $optlist : string = ""
Return values
mixed —setPDFLibParameter()
protected
setPDFLibParameter(string $keyword, string $value) : mixed
Parameters
- $keyword : string
- $value : string
Return values
mixed —setPDFLibValue()
protected
setPDFLibValue(string $keyword, string $value) : mixed
Parameters
- $keyword : string
- $value : string
Return values
mixed —y()
Remaps y coords from 4th to 1st quadrant
protected
y(float $y) : float
Parameters
- $y : float