| Cpdf

# Class: Cpdf Source Location: /lib/cpdf/class.pdf.php
### Class Overview
Cpdf #### Author(s): Wayne Munro <mailto:pdf@ros.co.nz> #### Version: 009 | ### Variables $addLooseObjects $arc4 $arc4_objnum $callback $catalogId $checkpoint $currentBaseFont $currentColour $currentContents $currentFont $currentFontNum $currentLineStyle $currentNode $currentPage $currentStrokeColour $currentTextState $destinations $encrypted $encryptionKey $fileIdentifier $firstPageId $fontFamilies $fonts $infoObject $looseObjects $messages $nCallback $nStack $nStateStack $numFonts $numImages $numObj $numPages $objects $options $procsetObjectId $stack $stateStack $wordSpaceAdjust | ### Methods Cpdf addDestination addImage addInfo addInternalLink addJpegFromFile addLink addMessage addObject addPngFromFile addText addTextAlignRight addTextWrap ARC4 ARC4_init checkAllHere closeObject curve ellipse encryptInit filledEllipse filledRectangle getFirstPageId getFontDecender getFontHeight getTextWidth line md5_16 newPage openHere openObject output o_action o_annotation o_catalog o_contents o_destination o_encryption o_font o_fontDescriptor o_fontEncoding o_image o_info o_outlines o_page o_pages o_procset o_viewerPreferences partEllipse polygon rectangle reopenObject restoreState saveState selectFont setColor setColorBy255 setEncryption setFontFamily setLineStyle setPreferences setStrokeColor setStrokeColorBy255 stopObject stream transaction
### Child classes: Cezpdf Cpdf | ### Inherited Variables | ### Inherited Methods
### Class Details [line 23] Cpdf http://www.ros.co.nz/pdf A PHP class to provide the basic functionality to create a pdf document without any requirement for additional modules. Note that they companion class CezPdf can be used to extend this class and dramatically simplify the creation of documents. IMPORTANT NOTE there is no warranty, implied or otherwise with this software. LICENCE This code has been placed in the Public Domain for all to enjoy. #### Tags:
version: | 009
author: | Wayne Munro <mailto:pdf@ros.co.nz>
[ Top ] ### Class Variables #### $addLooseObjects = array() [line 111] array contains infomation about how the loose objects are to be added to the document
Type: | mixed
[ Top ] #### $arc4 = '' [line 156] the ancryption array for the document encryption is stored here
Type: | mixed
[ Top ] #### $arc4_objnum = 0 [line 160] the object Id of the encryption information
Type: | mixed
[ Top ] #### $callback = array() [line 176] array which forms a stack to keep track of nested callback functions
Type: | mixed
[ Top ] #### $catalogId = [line 36] the objectId (number within the objects array) of the document catalog
Type: | mixed
[ Top ] #### $checkpoint = '' [line 191] store the stack for the transaction commands, each item in here is a record of the values of all the variables within the class, so that the user can rollback at will (from each 'start' command) note that this includes the objects array, so these can be large.
Type: | mixed
[ Top ] #### $currentBaseFont = '' [line 49] the current base font
Type: | mixed
[ Top ] #### $currentColour = array('r'=>-1,'g'=>-1,'b'=>-1) [line 73] current colour for fill operations, defaults to inactive value, all three components should be between 0 and 1 inclusive when active
Type: | mixed
[ Top ] #### $currentContents = [line 65] object number of the currently active contents block
Type: | mixed
[ Top ] #### $currentFont = '' [line 45] a record of the current font
Type: | mixed
[ Top ] #### $currentFontNum = 0 [line 53] the number of the current font within the font array
Type: | mixed
[ Top ] #### $currentLineStyle = '' [line 81] current style that lines are drawn in
Type: | mixed
[ Top ] #### $currentNode = [line 57]
Type: | mixed
[ Top ] #### $currentPage = [line 61] object number of the current page
Type: | mixed
[ Top ] #### $currentStrokeColour = array('r'=>-1,'g'=>-1,'b'=>-1) [line 77] current colour for stroke operations (lines etc.)
Type: | mixed
[ Top ] #### $currentTextState = '' [line 148] track if the current font is bolded or italicised
Type: | mixed
[ Top ] #### $destinations = array() [line 185] store label->id pairs for named destinations, these will be used to replace internal links done this way so that destinations can be defined after the location that links to them
Type: | mixed
[ Top ] #### $encrypted = 0 [line 168] a flag to say if a document is to be encrypted or not
Type: | mixed
[ Top ] #### $encryptionKey = '' [line 172] the ancryption key for the encryption of all the document content (structure is not encrypted)
Type: | mixed
[ Top ] #### $fileIdentifier = '' [line 164] the file identifier, used to uniquely identify a pdf document
Type: | mixed
[ Top ] #### $firstPageId = [line 129] the objectId of the first page of the document
Type: | mixed
[ Top ] #### $fontFamilies = array() [line 144] store the information about the relationship between font families this used so that the code knows which font is the bold version of another font, etc. the value of this array is initialised in the constuctor function.
Type: | mixed
[ Top ] #### $fonts = array() [line 41] array carrying information about the fonts that the system currently knows about used to ensure that a font is not loaded twice, among other things
Type: | mixed
[ Top ] #### $infoObject = 0 [line 116] the objectId of the information object for the document this contains authorship, title etc.
Type: | mixed
[ Top ] #### $looseObjects = array() [line 107] an array which contains information about the objects which are not firmly attached to pages these have been added with the addObject function
Type: | mixed
[ Top ] #### $messages = '' [line 152] messages are stored here during processing, these can be selected afterwards to give some useful debug information
Type: | mixed
[ Top ] #### $nCallback = 0 [line 180] the number of callback functions in the callback array
Type: | mixed
[ Top ] #### $nStack = 0 [line 102] number of elements within the object Id storage stack
Type: | mixed
[ Top ] #### $nStateStack = 0 [line 90] number of elements within the state stack
Type: | mixed
[ Top ] #### $numFonts = 0 [line 69] number of fonts within the system
Type: | mixed
[ Top ] #### $numImages = 0 [line 120] number of images being tracked within the document
Type: | mixed
[ Top ] #### $numObj = 0 [line 28] the current number of pdf objects in the document
Type: | mixed
[ Top ] #### $numPages = 0 [line 94] number of page objects within the document
Type: | mixed
[ Top ] #### $objects = array() [line 32] this array contains all of the pdf objects, ready for final assembly
Type: | mixed
[ Top ] #### $options = array('compression'=>1) [line 125] an array containing options about the document it defaults to turning on the compression of the objects
Type: | mixed
[ Top ] #### $procsetObjectId = [line 138] the object Id of the procset object
Type: | mixed
[ Top ] #### $stack = array() [line 98] object Id storage stack
Type: | mixed
[ Top ] #### $stateStack = array() [line 86] an array which is used to save the state of the document, mainly the colours and styles it is used to temporarily change to another state, the change back to what it was before
Type: | mixed
[ Top ] #### $wordSpaceAdjust = 0 [line 134] used to track the last used value of the inter-word spacing, this is so that it is known when the spacing is changed.
Type: | mixed
[ Top ] ### Class Methods ### constructor Cpdf [line 197]
`Cpdf Cpdf( [mixed $pageSize = array(0,0,612,792)])`
class constructor this will start a new document #### Tags:
var: | array of 4 numbers, defining the bottom left and upper right corner of the page. first two are normally zero.
[ Top ] ### method addDestination [line 3037]
`void addDestination( mixed $label, mixed $style, [mixed $a = 0], [mixed $b = 0], [mixed $c = 0])`
create a labelled destination within the document [ Top ] ### method addImage [line 2938]
`void addImage( mixed &$img, mixed $x, mixed $y, [mixed $w = 0], [mixed $h = 0], [mixed $quality = 75])`
add an image into the document, from a GD object this function is not all that reliable, and I would probably encourage people to use the file based functions [ Top ] ### method addInfo [line 2663]
`void addInfo( mixed $label, [mixed $value = 0])`
add content to the documents info object [ Top ] ### method addInternalLink [line 1173]
`void addInternalLink( mixed $label, mixed $x0, mixed $y0, mixed $x1, mixed $y1)`
add a link in the document to an internal destination (ie. within the document) [ Top ] ### method addJpegFromFile [line 2893]
`void addJpegFromFile( mixed $img, mixed $x, mixed $y, [mixed $w = 0], [mixed $h = 0])`
add a JPEG image into the document, from a file [ Top ] ### method addLink [line 1164]
`void addLink( mixed $url, mixed $x0, mixed $y0, mixed $x1, mixed $y1)`
add a link in the document to an external URL [ Top ] ### method addMessage [line 3090]
`void addMessage( mixed $message)`
used to add messages for use in debugging [ Top ] ### method addObject [line 2617]
`void addObject( mixed $id, [mixed $options = 'add'])`
after an object has been created, it wil only show if it has been added, using this function. [ Top ] ### method addPngFromFile [line 2710]
`void addPngFromFile( mixed $file, mixed $x, mixed $y, [mixed $w = 0], [mixed $h = 0])`
add a PNG image into the document, from a file this should work with remote files [ Top ] ### method addText [line 2205]
`void addText( mixed $x, mixed $y, mixed $size, mixed $text, [mixed $angle = 0], [mixed $wordSpaceAdjust = 0])`
add text to the document, at a specified location, size and angle on the page [ Top ] ### method addTextAlignRight [line 2384]
`void addTextAlignRight( int $x, int $y, int $size, string $text)`
#### Tags:
author: | andrej at blueshoes dot org
access: | public
#### Parameters:
int | $x | (x-axis, text will go to the left from there)
int | $y | (y-axis)
int | $size | (text size)
string | $text |
[ Top ] ### method addTextWrap [line 2396]
`void addTextWrap( mixed $x, mixed $y, mixed $width, mixed $size, mixed $text, [mixed $justification = 'left'], [mixed $angle = 0], [mixed $test = 0])`
add text to the page, but ensure that it fits within a certain width if it does not fit then put in as much as possible, splitting at word boundaries and return the remainder. justification and angle can also be specified for the text [ Top ] ### method ARC4 [line 1138]
`void ARC4( mixed $text)`
ARC4 encrypt a text string [ Top ] ### method ARC4_init [line 1112]
`void ARC4_init( [mixed $key = ''])`
initialize the ARC4 encryption [ Top ] ### method checkAllHere [line 1214]
`void checkAllHere( )`
should be used for internal checks, not implemented as yet [ Top ] ### method closeObject [line 2591]
`void closeObject( )`
close an object [ Top ] ### method curve [line 1729]
`void curve( mixed $x0, mixed $y0, mixed $x1, mixed $y1, mixed $x2, mixed $y2, mixed $x3, mixed $y3)`
draw a bezier curve based on 4 control points [ Top ] ### method ellipse [line 1760]
`void ellipse( mixed $x0, mixed $y0, mixed $r1, [mixed $r2 = 0], [mixed $angle = 0], [mixed $nSeg = 8], [mixed $astart = 0], [mixed $afinish = 360], [mixed $close = 1], [mixed $fill = 0])`
draw an ellipse note that the part and filled ellipse are just special cases of this function draws an ellipse in the current line style centered at $x0,$y0, radii $r1,$r2 if $r2 is not set, then a circle is drawn nSeg is not allowed to be less than 2, as this will simply draw a line (and will even draw a pretty crappy shape at 2, as we are approximating with bezier curves. [ Top ] ### method encryptInit [line 1098]
`void encryptInit( mixed $id)`
initialize the encryption for processing a particular object [ Top ] ### method filledEllipse [line 1746]
`void filledEllipse( mixed $x0, mixed $y0, mixed $r1, [mixed $r2 = 0], [mixed $angle = 0], [mixed $nSeg = 8], [mixed $astart = 0], [mixed $afinish = 360])`
draw a filled ellipse [ Top ] ### method filledRectangle [line 1882]
`void filledRectangle( mixed $x1, mixed $y1, mixed $width, mixed $height)`
a filled rectangle, note that it is the width and height of the rectangle which are the secondary paramaters, not the coordinates of the upper-right corner [ Top ] ### method getFirstPageId [line 1639]
`void getFirstPageId( )`
function for the user to find out what the ID is of the first page that was created during startup - useful if they wish to add something to it later. [ Top ] ### method getFontDecender [line 1990]
`void getFontDecender( mixed $size)`
return the font decender, this will normally return a negative number if you add this number to the baseline, you get the level of the bottom of the font it is in the pdf user units [ Top ] ### method getFontHeight [line 1976]
`void getFontHeight( mixed $size)`
return the height in units of the current font in the given size [ Top ] ### method getTextWidth [line 2297]
`void getTextWidth( mixed $size, mixed $text)`
calculate how wide a given text string will be on a page, at a given size. this can be called externally, but is alse used by the other class functions [ Top ] ### method line [line 1722]
`void line( mixed $x1, mixed $y1, mixed $x2, mixed $y2)`
draw a line from one set of coordinates to another [ Top ] ### method md5_16 [line 1086]
`void md5_16( mixed $string)`
calculate the 16 byte version of the 128 bit md5 digest of the string [ Top ] ### method newPage [line 1898]
`void newPage( [mixed $insert = 0], [mixed $id = 0], [mixed $pos = 'after'])`
add a new page to the document this also makes the new page the current active object [ Top ] ### method openHere [line 3017]
`void openHere( mixed $style, [mixed $a = 0], [mixed $b = 0], [mixed $c = 0])`
specify where the document should open when it first starts [ Top ] ### method openObject [line 2563]
`void openObject( )`
make a loose object, the output will go into this object, until it is closed, then will revert to the current one. this object will not appear until it is included within a page. the function will return the object number [ Top ] ### method output [line 1220]
`void output( [mixed $debug = 0])`
return the pdf stream as a string returned from the function [ Top ] ### method o_action [line 726]
`void o_action( mixed $id, mixed $action, [mixed $options = ''])`
an action object, used to link to URLS initially [ Top ] ### method o_annotation [line 769]
`void o_annotation( mixed $id, mixed $action, [mixed $options = ''])`
an annotation object, this will add an annotation to the current page. initially will support just link annotations [ Top ] ### method o_catalog [line 297]
`void o_catalog( mixed $id, mixed $action, [mixed $options = ''])`
define the document catalog, the overall controller for the document [ Top ] ### method o_contents [line 890]
`void o_contents( mixed $id, mixed $action, [mixed $options = ''])`
the contents objects hold all of the content which appears on pages [ Top ] ### method o_destination [line 224]
`void o_destination( mixed $id, mixed $action, [mixed $options = ''])`
destination object, used to specify the location for the user to jump to, presently on opening [ Top ] ### method o_encryption [line 1015]
`void o_encryption( mixed $id, mixed $action, [mixed $options = ''])`
encryption object. [ Top ] ### method o_font [line 475]
`void o_font( mixed $id, mixed $action, [mixed $options = ''])`
an object to hold the font description [ Top ] ### method o_fontDescriptor [line 559]
`void o_fontDescriptor( mixed $id, mixed $action, [mixed $options = ''])`
a font descriptor, needed for including additional fonts [ Top ] ### method o_fontEncoding [line 610]
`void o_fontEncoding( mixed $id, mixed $action, [mixed $options = ''])`
the font encoding [ Top ] ### method o_image [line 940]
`void o_image( mixed $id, mixed $action, [mixed $options = ''])`
an image object, will be an XObject in the document, includes description and data [ Top ] ### method o_info [line 682]
`void o_info( mixed $id, mixed $action, [mixed $options = ''])`
define the document information [ Top ] ### method o_outlines [line 445]
`void o_outlines( mixed $id, mixed $action, [mixed $options = ''])`
define the outlines in the doc, empty for now [ Top ] ### method o_page [line 821]
`void o_page( mixed $id, mixed $action, [mixed $options = ''])`
a page object, it also creates a contents object to hold its contents [ Top ] ### method o_pages [line 347]
`void o_pages( mixed $id, mixed $action, [mixed $options = ''])`
object which is a parent to the pages in the document [ Top ] ### method o_procset [line 647]
`void o_procset( mixed $id, mixed $action, [mixed $options = ''])`
the document procset, solves some problems with printing to old PS printers [ Top ] ### method o_viewerPreferences [line 259]
`void o_viewerPreferences( mixed $id, mixed $action, [mixed $options = ''])`
set the viewer preferences [ Top ] ### method partEllipse [line 1739]
`void partEllipse( mixed $x0, mixed $y0, mixed $astart, mixed $afinish, mixed $r1, [mixed $r2 = 0], [mixed $angle = 0], [mixed $nSeg = 8])`
draw a part of an ellipse [ Top ] ### method polygon [line 1865]
`void polygon( mixed $p, mixed $np, [mixed $f = 0])`
draw a polygon, the syntax for this is similar to the GD polygon command [ Top ] ### method rectangle [line 1890]
`void rectangle( mixed $x1, mixed $y1, mixed $width, mixed $height)`
draw a rectangle, note that it is the width and height of the rectangle which are the secondary paramaters, not the coordinates of the upper-right corner [ Top ] ### method reopenObject [line 2578]
`void reopenObject( mixed $id)`
open an existing object for editing [ Top ] ### method restoreState [line 2544]
`void restoreState( [mixed $pageEnd = 0])`
restore a previously saved state [ Top ] ### method saveState [line 2520]
`void saveState( [mixed $pageEnd = 0])`
this will be called at a new page to return the state to what it was on the end of the previous page, before the stack was closed down This is to get around not being able to have open 'q' across pages [ Top ] ### method selectFont [line 1417]
`void selectFont( mixed $fontName, [mixed $encoding = ''], [mixed $set = 1])`
if the font is not loaded then load it and make the required object else just make it the current font the encoding array can contain 'encoding'=> 'none','WinAnsiEncoding','MacRomanEncoding' or 'MacExpertEncoding' note that encoding='none' will need to be used for symbolic fonts and 'differences' => an array of mappings between numbers 0->255 and character names. [ Top ] ### method setColor [line 1657]
`void setColor( mixed $r, mixed $g, mixed $b, [mixed $force = 0])`
sets the colour for fill operations [ Top ] ### method setColorBy255 [line 1679]
`void setColorBy255( int $r, int $g, int $b, [int $force = 0])`
like setColor() but uses values from 0-255 instead of 0-1. #### Tags:
author: | andrej at blueshoes dot org
access: | public
#### Parameters:
int | $r | (red color value, 0-255.)
int | $g | (green color value, 0-255.)
int | $b | (blue color value, 0-255.)
int | $force | (0 or 1, like in setColor().)
[ Top ] ### method setEncryption [line 1184]
`void setEncryption( [mixed $userPass = ''], [mixed $ownerPass = ''], [mixed $pc = array()])`
set the encryption of the document can be used to turn it on and/or set the passwords which it will have. also the functions that the user will have are set here, such as print, modify, add [ Top ] ### method setFontFamily [line 3053]
`void setFontFamily( mixed $family, [mixed $options = ''])`
define font families, this is used to initialize the font families for the default fonts and for the user to add new ones for their fonts. The default bahavious can be overridden should that be desired. [ Top ] ### method setLineStyle [line 1836]
`void setLineStyle( [mixed $width = 1], [mixed $cap = ''], [mixed $join = ''], [mixed $dash = ''], [mixed $phase = 0])`
this sets the line drawing style. width, is the thickness of the line in user units cap is the type of cap to put on the line, values can be 'butt','round','square' where the diffference between 'square' and 'butt' is that 'square' projects a flat end past the end of the line. join can be 'miter', 'round', 'bevel' dash is an array which sets the dash pattern, is a series of length values, which are the lengths of the on and off dashes. (2) represents 2 on, 2 off, 2 on , 2 off ... (2,1) is 2 on, 1 off, 2 on, 1 off.. etc phase is a modifier on the dash pattern which is used to shift the point at which the pattern starts. [ Top ] ### method setPreferences [line 2680]
`void setPreferences( mixed $label, [mixed $value = 0])`
set the viewer preferences of the document, it is up to the browser to obey these. [ Top ] ### method setStrokeColor [line 1690]
`void setStrokeColor( mixed $r, mixed $g, mixed $b, [mixed $force = 0])`
sets the colour for stroke operations [ Top ] ### method setStrokeColorBy255 [line 1712]
`void setStrokeColorBy255( int $r, int $g, int $b, [int $force = 0])`
like setStrokeColor() but uses values from 0-255 instead of 0-1. #### Tags:
author: | andrej at blueshoes dot org
access: | public
#### Parameters:
int | $r | (red color value, 0-255.)
int | $g | (green color value, 0-255.)
int | $b | (blue color value, 0-255.)
int | $force | (0 or 1, like in setStrokeColor().)
[ Top ] ### method stopObject [line 2606]
`void stopObject( mixed $id)`
stop an object from appearing on pages from this point on [ Top ] ### method stream [line 1946]
`void stream( [mixed $options = ''])`
output the pdf code, streaming it to the browser the relevant headers are set so that hopefully the browser will recognise it [ Top ] ### method transaction [line 3097]
`void transaction( mixed $action)`
a few functions which should allow the document to be treated transactionally. [ Top ] Documentation generated on Mon, 29 Dec 2003 21:13:38 +0100 by phpDocumentor 1.2.3