PHP Class Pop\Pdf\Pdf

Author: Nick Sagona, III ([email protected])
Inheritance: extends Pop\Pdf\AbstractPdf
Exibir arquivo Open project: nicksagona/PopPHP Class Usage Examples

Protected Properties

Property Type Description
$allowed array Array of allowed file types.
$backgroundColor mixed Background color of the document
$bytelength integer PDF bytelength
$compress boolean Compression property
$curPage integer Current PDF page.
$fillColor mixed Fill color of the document
$fonts array Current fonts added to the PDF
$images string Array of images added to the PDF
$info integer PDF info index.
$lastFontName string Last font name
$objects array Array of PDF objects.
$pages array Array of PDF page object indices.
$parent integer PDF parent index.
$root integer PDF root index.
$standardFonts array Standard PDF fonts with their approximate character width and height factors.
$stroke boolean Stroke ON or OFF flag
$strokeColor mixed Stroke color of the document
$strokeDashGap integer Stroke dash gap
$strokeDashLength integer Stroke dash length
$strokeWidth integer Stroke width
$textParams array PDF text parameters.
$trailer string PDF trailer.

Public Methods

Method Description
__construct ( string $pdf, string $sz = null, integer $w = null, integer $h = null ) : Pdf Constructor
addFont ( string $font, boolean $embedOverride = false ) : Pdf Method to add a font to the PDF.
addImage ( string $image, integer $x, integer $y, mixed $scl = null, boolean $preserveRes = true ) : Pdf Method to add an image to the PDF.
addLink ( integer $x, integer $y, integer $w, integer $h, integer $X, integer $Y, integer $Z, integer $dest = null ) : Pdf Method to add an internal link to the PDF.
addPage ( string $sz = null, integer $w = null, integer $h = null ) : Pdf Method to add a page to the PDF of a determined size.
addText ( integer $x, integer $y, integer $size, string $str, string $font = null ) : Pdf Method to add text to the PDF.
addUrl ( integer $x, integer $y, integer $w, integer $h, string $url ) : Pdf Method to add a URL link to the PDF.
closeLayer ( ) : Pdf Method to close a new graphics state layer within the PDF.
copyPage ( integer $pg ) : Pdf Method to copy a page of the PDF.
curPage ( ) : integer Method to return the current page number of the current page of the PDF.
deletePage ( integer $pg ) : Pdf Method to delete the page of the PDF and its content objects.
drawArc ( integer $x, integer $y, integer $start, integer $end, integer $w, integer $h = null, boolean $fill = true ) : Pdf Method to add an arc to the PDF.
drawCircle ( integer $x, integer $y, integer $w, boolean $fill = true ) : Pdf Method to add a circle to the PDF.
drawClippingCircle ( integer $x, integer $y, integer $w ) : Pdf Method to add a clipping circle to the PDF.
drawClippingEllipse ( integer $x, integer $y, integer $w, integer $h = null ) : Pdf Method to add a clipping ellipse to the PDF.
drawClippingPolygon ( array $points ) : Pdf Method to add a clipping polygon to the PDF.
drawClippingRectangle ( integer $x, integer $y, integer $w, integer $h = null ) : Pdf Method to add a clipping rectangle to the PDF.
drawClippingSquare ( integer $x, integer $y, integer $w ) : Pdf Method to add a clipping square to the PDF.
drawEllipse ( integer $x, integer $y, integer $w, integer $h = null, boolean $fill = true ) : Pdf Method to add an ellipse to the PDF.
drawLine ( integer $x1, integer $y1, integer $x2, integer $y2 ) : Pdf Method to add a line to the PDF.
drawPolygon ( array $points, boolean $fill = true ) : Pdf Method to add a polygon to the image.
drawRectangle ( integer $x, integer $y, integer $w, integer $h = null, boolean $fill = true ) : Pdf Method to add a rectangle to the PDF.
drawSquare ( integer $x, integer $y, integer $w, boolean $fill = true ) : Pdf Method to add a square to the PDF.
finalize ( ) : Pdf Method to finalize the PDF.
getCompression ( ) : boolean Method to get the compression of the PDF.
getFonts ( ) : string Method to return the name of the last font added.
getLastFontName ( ) : string Method to return the name of the last font added.
getStringSize ( string $str, string $font, integer $sz ) : array Method to get the width and height of a string in a certain font. It returns an array with the approximate width, height and offset baseline values.
import ( string $pdf, integer | string | array $pg = null ) : Pdf Method to import either an entire PDF, or a page of a PDF, and the related data.
numPages ( ) : integer Method to return the current number of pages in the PDF.
openLayer ( ) : Pdf Method to open a new graphics state layer within the PDF.
orderPages ( array $pgs ) : Pdf Method to order the pages of the PDF.
output ( boolean $download = false ) : void Output the PDF directly to the browser.
save ( string $to = null, boolean $append = false ) : Pdf Save the PDF directly to the server.
setAuthor ( string $auth ) : Pdf Method to set the PDF info author.
setBackgroundColor ( Pop\Color\Space\ColorInterface $color ) : Pdf Method to set the background of the document.
setCompression ( boolean $comp = false ) : Pdf Method to set the compression of the PDF.
setCreateDate ( string $dt ) : Pdf Method to set the PDF info creation date.
setFillColor ( Pop\Color\Space\ColorInterface $color ) : Pdf Method to set the fill color of objects and text in the PDF.
setModDate ( string $dt ) : Pdf Method to set the PDF info modification date.
setPage ( integer $pg ) : Pdf Method to set the current page of the PDF in which to edit.
setStrokeColor ( Pop\Color\Space\ColorInterface $color ) : Pdf Method to set the stroke color of paths in the PDF.
setStrokeWidth ( integer $w = null, integer $dash_len = null, integer $dash_gap = null ) : Pdf Method to set the width and dash properties of paths in the PDF.
setSubject ( string $subj ) : Pdf Method to set the PDF info subject.
setTextParams ( integer $c, integer $w, integer $h = 100, integer $v = 100, integer $rot, integer $rend ) : Pdf Method to set the text parameters for rendering text content.
setTitle ( string $tle ) : Pdf Method to set the PDF info title.
setVersion ( string $ver ) : Pdf Method to set the PDF version.

Protected Methods

Method Description
calcByteLength ( string $str ) : integer Method to calculate byte length.
calcTextMatrix ( ) : string Method to calculate text matrix.
convertColor ( integer | string $color ) : float Method to convert color.
formatByteLength ( integer | string $num ) : string Method to format byte length.
getContentObject ( ) : integer Method to return the current page's content object, or create one if necessary.
getQuadrant ( array $point, array $center ) : integer Method to calculate which quadrant a point is in.
lastIndex ( array $arr ) : integer Method to return the last object index.
setStyle ( boolean $fill ) : string Method to set the fill/stroke style.

Method Details

__construct() public method

Instantiate a PDF file object based on either a pre-existing PDF file on disk, or a new PDF file. Arguments may be passed to add a page upon instantiation. The PDF file exists, it and all of its assets will be imported.
public __construct ( string $pdf, string $sz = null, integer $w = null, integer $h = null ) : Pdf
$pdf string
$sz string
$w integer
$h integer
return Pdf

addFont() public method

Method to add a font to the PDF.
public addFont ( string $font, boolean $embedOverride = false ) : Pdf
$font string
$embedOverride boolean
return Pdf

addImage() public method

Method to add an image to the PDF.
public addImage ( string $image, integer $x, integer $y, mixed $scl = null, boolean $preserveRes = true ) : Pdf
$image string
$x integer
$y integer
$scl mixed
$preserveRes boolean
return Pdf

addPage() public method

Method to add a page to the PDF of a determined size.
public addPage ( string $sz = null, integer $w = null, integer $h = null ) : Pdf
$sz string
$w integer
$h integer
return Pdf

addText() public method

Method to add text to the PDF.
public addText ( integer $x, integer $y, integer $size, string $str, string $font = null ) : Pdf
$x integer
$y integer
$size integer
$str string
$font string
return Pdf

addUrl() public method

Method to add a URL link to the PDF.
public addUrl ( integer $x, integer $y, integer $w, integer $h, string $url ) : Pdf
$x integer
$y integer
$w integer
$h integer
$url string
return Pdf

calcByteLength() protected method

Method to calculate byte length.
protected calcByteLength ( string $str ) : integer
$str string
return integer

calcTextMatrix() protected method

Method to calculate text matrix.
protected calcTextMatrix ( ) : string
return string

closeLayer() public method

Must be used in conjunction with the openLayer() method.
public closeLayer ( ) : Pdf
return Pdf

convertColor() protected method

Method to convert color.
protected convertColor ( integer | string $color ) : float
$color integer | string
return float

copyPage() public method

Method to copy a page of the PDF.
public copyPage ( integer $pg ) : Pdf
$pg integer
return Pdf

curPage() public method

Method to return the current page number of the current page of the PDF.
public curPage ( ) : integer
return integer

deletePage() public method

Method to delete the page of the PDF and its content objects.
public deletePage ( integer $pg ) : Pdf
$pg integer
return Pdf

drawArc() public method

Method to add an arc to the PDF.
public drawArc ( integer $x, integer $y, integer $start, integer $end, integer $w, integer $h = null, boolean $fill = true ) : Pdf
$x integer
$y integer
$start integer
$end integer
$w integer
$h integer
$fill boolean
return Pdf

drawCircle() public method

Method to add a circle to the PDF.
public drawCircle ( integer $x, integer $y, integer $w, boolean $fill = true ) : Pdf
$x integer
$y integer
$w integer
$fill boolean
return Pdf

drawClippingCircle() public method

Method to add a clipping circle to the PDF.
public drawClippingCircle ( integer $x, integer $y, integer $w ) : Pdf
$x integer
$y integer
$w integer
return Pdf

drawClippingEllipse() public method

Method to add a clipping ellipse to the PDF.
public drawClippingEllipse ( integer $x, integer $y, integer $w, integer $h = null ) : Pdf
$x integer
$y integer
$w integer
$h integer
return Pdf

drawClippingPolygon() public method

Method to add a clipping polygon to the PDF.
public drawClippingPolygon ( array $points ) : Pdf
$points array
return Pdf

drawClippingRectangle() public method

Method to add a clipping rectangle to the PDF.
public drawClippingRectangle ( integer $x, integer $y, integer $w, integer $h = null ) : Pdf
$x integer
$y integer
$w integer
$h integer
return Pdf

drawClippingSquare() public method

Method to add a clipping square to the PDF.
public drawClippingSquare ( integer $x, integer $y, integer $w ) : Pdf
$x integer
$y integer
$w integer
return Pdf

drawEllipse() public method

Method to add an ellipse to the PDF.
public drawEllipse ( integer $x, integer $y, integer $w, integer $h = null, boolean $fill = true ) : Pdf
$x integer
$y integer
$w integer
$h integer
$fill boolean
return Pdf

drawLine() public method

Method to add a line to the PDF.
public drawLine ( integer $x1, integer $y1, integer $x2, integer $y2 ) : Pdf
$x1 integer
$y1 integer
$x2 integer
$y2 integer
return Pdf

drawPolygon() public method

Method to add a polygon to the image.
public drawPolygon ( array $points, boolean $fill = true ) : Pdf
$points array
$fill boolean
return Pdf

drawRectangle() public method

Method to add a rectangle to the PDF.
public drawRectangle ( integer $x, integer $y, integer $w, integer $h = null, boolean $fill = true ) : Pdf
$x integer
$y integer
$w integer
$h integer
$fill boolean
return Pdf

drawSquare() public method

Method to add a square to the PDF.
public drawSquare ( integer $x, integer $y, integer $w, boolean $fill = true ) : Pdf
$x integer
$y integer
$w integer
$fill boolean
return Pdf

finalize() public method

Method to finalize the PDF.
public finalize ( ) : Pdf
return Pdf

formatByteLength() protected method

Method to format byte length.
protected formatByteLength ( integer | string $num ) : string
$num integer | string
return string

getCompression() public method

Method to get the compression of the PDF.
public getCompression ( ) : boolean
return boolean

getContentObject() protected method

Method to return the current page's content object, or create one if necessary.
protected getContentObject ( ) : integer
return integer

getFonts() public method

Method to return the name of the last font added.
public getFonts ( ) : string
return string

getLastFontName() public method

Method to return the name of the last font added.
public getLastFontName ( ) : string
return string

getQuadrant() protected method

Method to calculate which quadrant a point is in.
protected getQuadrant ( array $point, array $center ) : integer
$point array
$center array
return integer

getStringSize() public method

Method to get the width and height of a string in a certain font. It returns an array with the approximate width, height and offset baseline values.
public getStringSize ( string $str, string $font, integer $sz ) : array
$str string
$font string
$sz integer
return array

import() public method

Method to import either an entire PDF, or a page of a PDF, and the related data.
public import ( string $pdf, integer | string | array $pg = null ) : Pdf
$pdf string
$pg integer | string | array
return Pdf

lastIndex() protected method

Method to return the last object index.
protected lastIndex ( array $arr ) : integer
$arr array
return integer

numPages() public method

Method to return the current number of pages in the PDF.
public numPages ( ) : integer
return integer

openLayer() public method

Must be used in conjunction with the closeLayer() method.
public openLayer ( ) : Pdf
return Pdf

orderPages() public method

Method to order the pages of the PDF.
public orderPages ( array $pgs ) : Pdf
$pgs array
return Pdf

output() public method

Output the PDF directly to the browser.
public output ( boolean $download = false ) : void
$download boolean
return void

save() public method

Save the PDF directly to the server.
public save ( string $to = null, boolean $append = false ) : Pdf
$to string
$append boolean
return Pdf

setAuthor() public method

Method to set the PDF info author.
public setAuthor ( string $auth ) : Pdf
$auth string
return Pdf

setBackgroundColor() public method

Method to set the background of the document.
public setBackgroundColor ( Pop\Color\Space\ColorInterface $color ) : Pdf
$color Pop\Color\Space\ColorInterface
return Pdf

setCompression() public method

Method to set the compression of the PDF.
public setCompression ( boolean $comp = false ) : Pdf
$comp boolean
return Pdf

setCreateDate() public method

Method to set the PDF info creation date.
public setCreateDate ( string $dt ) : Pdf
$dt string
return Pdf

setFillColor() public method

Method to set the fill color of objects and text in the PDF.
public setFillColor ( Pop\Color\Space\ColorInterface $color ) : Pdf
$color Pop\Color\Space\ColorInterface
return Pdf

setModDate() public method

Method to set the PDF info modification date.
public setModDate ( string $dt ) : Pdf
$dt string
return Pdf

setPage() public method

Method to set the current page of the PDF in which to edit.
public setPage ( integer $pg ) : Pdf
$pg integer
return Pdf

setStrokeColor() public method

Method to set the stroke color of paths in the PDF.
public setStrokeColor ( Pop\Color\Space\ColorInterface $color ) : Pdf
$color Pop\Color\Space\ColorInterface
return Pdf

setStrokeWidth() public method

Method to set the width and dash properties of paths in the PDF.
public setStrokeWidth ( integer $w = null, integer $dash_len = null, integer $dash_gap = null ) : Pdf
$w integer
$dash_len integer
$dash_gap integer
return Pdf

setStyle() protected method

Method to set the fill/stroke style.
protected setStyle ( boolean $fill ) : string
$fill boolean
return string

setSubject() public method

Method to set the PDF info subject.
public setSubject ( string $subj ) : Pdf
$subj string
return Pdf

setTextParams() public method

Method to set the text parameters for rendering text content.
public setTextParams ( integer $c, integer $w, integer $h = 100, integer $v = 100, integer $rot, integer $rend ) : Pdf
$c integer (character spacing)
$w integer (word spacing)
$h integer (horz stretch)
$v integer (vert stretch)
$rot integer (rotation)
$rend integer (render flag, 0 - 7)
return Pdf

setTitle() public method

Method to set the PDF info title.
public setTitle ( string $tle ) : Pdf
$tle string
return Pdf

setVersion() public method

Method to set the PDF version.
public setVersion ( string $ver ) : Pdf
$ver string
return Pdf

Property Details

$allowed protected_oe property

Array of allowed file types.
protected array $allowed
return array

$backgroundColor protected_oe property

Background color of the document
protected mixed $backgroundColor
return mixed

$bytelength protected_oe property

PDF bytelength
protected int $bytelength
return integer

$compress protected_oe property

Compression property
protected bool $compress
return boolean

$curPage protected_oe property

Current PDF page.
protected int $curPage
return integer

$fillColor protected_oe property

Fill color of the document
protected mixed $fillColor
return mixed

$fonts protected_oe property

Current fonts added to the PDF
protected array $fonts
return array

$images protected_oe property

Array of images added to the PDF
protected string $images
return string

$info protected_oe property

PDF info index.
protected int $info
return integer

$lastFontName protected_oe property

Last font name
protected string $lastFontName
return string

$objects protected_oe property

Array of PDF objects.
protected array $objects
return array

$pages protected_oe property

Array of PDF page object indices.
protected array $pages
return array

$parent protected_oe property

PDF parent index.
protected int $parent
return integer

$root protected_oe property

PDF root index.
protected int $root
return integer

$standardFonts protected_oe property

Standard PDF fonts with their approximate character width and height factors.
protected array $standardFonts
return array

$stroke protected_oe property

Stroke ON or OFF flag
protected bool $stroke
return boolean

$strokeColor protected_oe property

Stroke color of the document
protected mixed $strokeColor
return mixed

$strokeDashGap protected_oe property

Stroke dash gap
protected int $strokeDashGap
return integer

$strokeDashLength protected_oe property

Stroke dash length
protected int $strokeDashLength
return integer

$strokeWidth protected_oe property

Stroke width
protected int $strokeWidth
return integer

$textParams protected_oe property

PDF text parameters.
protected array $textParams
return array

$trailer protected_oe property

PDF trailer.
protected string $trailer
return string