Pdf driver based on TCPDF
TCPDF is a PHP based PDF renderer, originally based on FPDF and available at http://tcpdf.org.
The TCPDF class has to be loaded before this driver can be used. TCPDF has some bad coding practices, like:
The driver can be used by setting the respective option on the PDF document wrapper, you need to download and load the TCPDF implementation yourself.
Source for this file: /Document/src/document/pdf/driver/tcpdf.php
ezcDocumentPdfDriver | --ezcDocumentPdfTcpdfDriver
Version: | //autogen// |
From ezcDocumentPdfDriver: | |
---|---|
ezcDocumentPdfDriver::FONT_BOLD
|
Bold text |
ezcDocumentPdfDriver::FONT_OBLIQUE
|
Italic text |
ezcDocumentPdfDriver::FONT_PLAIN
|
Normal text |
protected array |
$currentFont
= array(
Name and style of default font / currently used font |
protected haruPage |
$currentpage
Reference to the page currently rendered on |
protected Tcpdf |
$document
Tcpdf Document instance |
protected array |
$fonts
= array(
Array with fonts, and their equivalents for bold and italic markup. This array will be extended when loading new fonts, but contains the builtin fonts by default. The fourth value for each font is bold + oblique, the index is the bitwise and combination of the repective combinations. Each font MUST have at least a value for FONT_PLAIN assigned. |
protected array |
$internalLinkSources
= array()
Internal targets Link identifiers groupd by target names for all links in the document, which should be associated with the target at the end of the document rendering. |
protected array |
$internalTargets
= array()
Internal targets Target objects for all rendered internal targets, to be used when rendering the internal links at the end of the processing. |
protected array |
$pages
Page instances, given as an array, indexed by their page number starting with 0. |
protected array |
$permissionMapping
= array(
Mapping of native permission flags, to Haru permission flags |
From ezcDocumentPdfDriver | |
---|---|
protected |
ezcDocumentPdfDriver::$options
|
public void |
__construct(
)
Construct driver |
public void |
addExternalLink(
$x
, $y
, $width
, $height
, $url
)
Add an external link |
public void |
addInternalLink(
$x
, $y
, $width
, $height
, $target
)
Add an internal link |
public void |
addInternalLinkTarget(
$id
)
Add an internal link target |
public float |
calculateWordWidth(
$word
)
Calculate the rendered width of the current word |
public void |
createPage(
$width
, $height
)
Create a new page |
public void |
drawImage(
$file
, $type
, $x
, $y
, $width
, $height
)
Draw image |
public void |
drawPolygon(
$points
, $color
)
Draw a fileld polygon |
public void |
drawPolyline(
$points
, $color
, $width
, [ $close
= true] )
Draw a polyline |
public void |
drawWord(
$x
, $y
, $word
)
Draw word at given position |
public float |
getCurrentLineHeight(
)
Get current line height |
protected array |
getPointsArray(
$points
)
Transform points array into a TCPDF points array. |
protected void |
initialize(
)
Initialize haru documents |
public void |
registerFont(
$name
, $type
, $pathes
)
Register a font |
protected void |
renderInternalLinks(
)
Render internal links |
public string |
save(
)
Generate and return PDF |
public void |
setMetaData(
$key
, $value
)
Set metadata |
protected void |
setPermissions(
$options
, $permissions
)
Set permissions for PDF document |
public void |
setTextFormatting(
$type
, $value
)
Set text formatting option |
public void |
trySetFont(
$name
, $style
)
Try to set font |
From ezcDocumentPdfDriver | |
---|---|
public void |
ezcDocumentPdfDriver::__construct()
Construct driver |
public void |
ezcDocumentPdfDriver::addExternalLink()
Add an external link |
public void |
ezcDocumentPdfDriver::addInternalLink()
Add an internal link |
public void |
ezcDocumentPdfDriver::addInternalLinkTarget()
Add an internal link target |
public abstract float |
ezcDocumentPdfDriver::calculateWordWidth()
Calculate the rendered width of the current word |
public abstract void |
ezcDocumentPdfDriver::createPage()
Create a new page |
public abstract void |
ezcDocumentPdfDriver::drawImage()
Draw image |
public void |
ezcDocumentPdfDriver::drawPolygon()
Draw a fileld polygon |
public void |
ezcDocumentPdfDriver::drawPolyline()
Draw a polyline |
public abstract void |
ezcDocumentPdfDriver::drawWord()
Draw word at given position |
public abstract float |
ezcDocumentPdfDriver::getCurrentLineHeight()
Get current line height |
public void |
ezcDocumentPdfDriver::registerFont()
Register a font |
public abstract string |
ezcDocumentPdfDriver::save()
Generate and return PDF |
public void |
ezcDocumentPdfDriver::setMetaData()
Set metadata |
public void |
ezcDocumentPdfDriver::setOptions()
Set compression |
public abstract void |
ezcDocumentPdfDriver::setTextFormatting()
Set text formatting option |
Construct driver
Creates a new document instance maintaining all document context.
Method | Description |
---|---|
ezcDocumentPdfDriver::__construct() |
Construct driver |
Add an external link
Add an external link to the rectangle specified by its top-left position, width and height. The last parameter is the actual URL to link to.
Name | Type | Description |
---|---|---|
$x |
float | |
$y |
float | |
$width |
float | |
$height |
float | |
$url |
string |
Method | Description |
---|---|
ezcDocumentPdfDriver::addExternalLink() |
Add an external link |
Add an internal link
Add an internal link to the rectangle specified by its top-left position, width and height. The last parameter is the target identifier to link to.
Name | Type | Description |
---|---|---|
$x |
float | |
$y |
float | |
$width |
float | |
$height |
float | |
$target |
string |
Method | Description |
---|---|
ezcDocumentPdfDriver::addInternalLink() |
Add an internal link |
Add an internal link target
Add an internal link to the current page. The last parameter is the target identifier.
Name | Type | Description |
---|---|---|
$id |
string |
Method | Description |
---|---|
ezcDocumentPdfDriver::addInternalLinkTarget() |
Add an internal link target |
Calculate the rendered width of the current word
Calculate the width of the passed word, using the currently set text formatting options.
Name | Type | Description |
---|---|---|
$word |
string |
Method | Description |
---|---|
ezcDocumentPdfDriver::calculateWordWidth() |
Calculate the rendered width of the current word |
Create a new page
Create a new page in the PDF document with the given width and height.
Name | Type | Description |
---|---|---|
$width |
float | |
$height |
float |
Method | Description |
---|---|
ezcDocumentPdfDriver::createPage() |
Create a new page |
Draw image
Draw image at the defined position. The first parameter is the (absolute) path to the image file, and the second defines the type of the image. If the driver cannot handle this aprticular image type, it should throw an exception.
The further parameters define the location where the image should be rendered and the dimensions of the image in the rendered output. The dimensions do not neccesarily match the real image dimensions, and might require some kind of scaling inside the driver depending on the used backend.
Name | Type | Description |
---|---|---|
$file |
string | |
$type |
string | |
$x |
float | |
$y |
float | |
$width |
float | |
$height |
float |
Method | Description |
---|---|
ezcDocumentPdfDriver::drawImage() |
Draw image |
Draw a fileld polygon
Draw any filled polygon, filled using the defined color. The color should be passed as an array with the keys "red", "green", "blue" and optionally "alpha". Each key should have a value between 0 and 1 associated.
The polygon itself is specified as an array of two-tuples, specifying the x and y coordinate of the point.
Name | Type | Description |
---|---|---|
$points |
array | |
$color |
array |
Method | Description |
---|---|
ezcDocumentPdfDriver::drawPolygon() |
Draw a fileld polygon |
Draw a polyline
Draw any non-filled polygon, filled using the defined color. The color should be passed as an array with the keys "red", "green", "blue" and optionally "alpha". Each key should have a value between 0 and 1 associated.
The polyline itself is specified as an array of two-tuples, specifying the x and y coordinate of the point.
The thrid parameter defines the width of the border and the last parameter may optionally be set to false to not close the polygon (draw another line from the last point to the first one).
Name | Type | Description |
---|---|---|
$points |
array | |
$color |
array | |
$width |
float | |
$close |
bool |
Method | Description |
---|---|
ezcDocumentPdfDriver::drawPolyline() |
Draw a polyline |
Draw word at given position
Draw the given word at the given position using the currently set text formatting options.
The coordinate specifies the left bottom edge of the words bounding box.
Name | Type | Description |
---|---|---|
$x |
float | |
$y |
float | |
$word |
string |
Method | Description |
---|---|
ezcDocumentPdfDriver::drawWord() |
Draw word at given position |
Get current line height
Return the current line height in millimeter based on the current font and text rendering settings.
Method | Description |
---|---|
ezcDocumentPdfDriver::getCurrentLineHeight() |
Get current line height |
Transform points array into a TCPDF points array.
Name | Type | Description |
---|---|---|
$points |
array |
Initialize haru documents
Register a font
Registers a font, which can be used by its name later in the driver. The given type is either self::FONT_PLAIN or a bitwise combination of self::FONT_BOLD and self::FONT_OBLIQUE.
The third paramater specifies an array of pathes with references to font definition files. Multiple pathes may be specified to provide the same font using different types, because not all drivers may process all font types.
Name | Type | Description |
---|---|---|
$name |
string | |
$type |
int | |
$pathes |
array |
Method | Description |
---|---|
ezcDocumentPdfDriver::registerFont() |
Register a font |
Render internal links
Link identifiers groupd by target names for all links in the document, which should be associated with the target at the end of the document rendering.
Generate and return PDF
Return the generated binary PDF content as a string.
Method | Description |
---|---|
ezcDocumentPdfDriver::save() |
Generate and return PDF |
Set metadata
Set document meta data. The meta data types are identified by a list of keys, common to PDF, like: title, author, subject, created, modified.
The values are passed like embedded in the docbook document and might need to be reformatted.
Name | Type | Description |
---|---|---|
$key |
string | |
$value |
string |
Method | Description |
---|---|
ezcDocumentPdfDriver::setMetaData() |
Set metadata |
Set permissions for PDF document
Name | Type | Description |
---|---|---|
$permissions |
int | |
$options |
ezcDocumentPdfOptions |
Set text formatting option
Set a text formatting option. The names of the options are the same used in the PCSS files and need to be translated by the driver to the proper backend calls.
Name | Type | Description |
---|---|---|
$type |
string | |
$value |
mixed |
Method | Description |
---|---|
ezcDocumentPdfDriver::setTextFormatting() |
Set text formatting option |
Try to set font
Stays with the old font, if the newly specified font is not available.
If the font does not support the given style, it falls back to the style used beforehand, and if this is also not support the plain style will be used.
Name | Type | Description |
---|---|---|
$name |
string | |
$style |
int |