lib/ezpdf/classes/class.pdf.php

Show: inherited
Table of Contents

File containing the Cpdf class.

Copyright
Copyright (C) 1999-2011 eZ Systems AS. All rights reserved.  
License
eZ Business Use License Agreement Version 2.0  
Package
lib  
Version
4.6.0  

\Cpdf

Package: lib

File containing the Cpdf class.

Children
\Cezpdf
Copyright
Copyright (C) 1999-2011 eZ Systems AS. All rights reserved.  
License
eZ Business Use License Agreement Version 2.0  
Version
4.6.0  

Properties

Propertypublic  $addLooseObjects= 'array()'

array contains infomation about how the loose objects are to be added to the document

Default valuearray()Details
Type
n/a
Propertypublic  $arc4= ''''

the ancryption array for the document encryption is stored here

Default value''Details
Type
n/a
Propertypublic  $arc4_objnum= '0'

the object Id of the encryption information

Default value0Details
Type
n/a
Propertypublic  $callback= 'array()'

array which forms a stack to keep track of nested callback functions

Default valuearray()Details
Type
n/a
Propertypublic  $catalogId= ''

the objectId (number within the objects array) of the document catalog

Details
Type
n/a
Propertypublic  $checkpoint= ''''

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.

Default value''Details
Type
n/a
Propertypublic  $currentBaseFont= ''''

the current base font

Default value''Details
Type
n/a
Propertypublic  $currentColour= ''

current colour for fill operations, defaults to inactive value, all three components should be between 0 and 1 inclusive when active

Details
Type
n/a
Propertypublic  $currentContents= ''

object number of the currently active contents block

Details
Type
n/a
Propertypublic  $currentFont= ''''

a record of the current font

Default value''Details
Type
n/a
Propertypublic  $currentFontNum= '0'

the number of the current font within the font array

Default value0Details
Type
n/a
Propertypublic  $currentLineStyle= ''''

current style that lines are drawn in

Default value''Details
Type
n/a
Propertypublic  $currentNode= ''

Details
Type
n/a
Propertypublic  $currentPage= ''

object number of the current page

Details
Type
n/a
Propertypublic  $currentStrokeColour= ''

current colour for stroke operations (lines etc.)

Details
Type
n/a
Propertypublic  $currentTextState= ''''

track if the current font is bolded or italicised

Default value''Details
Type
n/a
Propertypublic  $destinations= 'array()'

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

Default valuearray()Details
Type
n/a
Propertypublic  $encrypted= '0'

a flag to say if a document is to be encrypted or not

Default value0Details
Type
n/a
Propertypublic  $encryptionKey= ''''

the ancryption key for the encryption of all the document content (structure is not encrypted)

Default value''Details
Type
n/a
Propertypublic  $fileIdentifier= ''''

the file identifier, used to uniquely identify a pdf document

Default value''Details
Type
n/a
Propertypublic  $firstPageId= ''

the objectId of the first page of the document

Details
Type
n/a
Propertypublic  $fontFamilies= 'array()'

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.

Default valuearray()Details
Type
n/a
Propertypublic  $fonts= 'array()'

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

Default valuearray()Details
Type
n/a
Propertypublic  $infoObject= '0'

the objectId of the information object for the document this contains authorship, title etc.

Default value0Details
Type
n/a
Propertypublic  $looseObjects= 'array()'

an array which contains information about the objects which are not firmly attached to pages these have been added with the addObject function

Default valuearray()Details
Type
n/a
Propertypublic  $messages= ''''

messages are stored here during processing, these can be selected afterwards to give some useful debug information

Default value''Details
Type
n/a
Propertypublic  $nCallback= '0'

the number of callback functions in the callback array

Default value0Details
Type
n/a
Propertypublic  $nStack= '0'

number of elements within the object Id storage stack

Default value0Details
Type
n/a
Propertypublic  $nStateStack= '0'

number of elements within the state stack

Default value0Details
Type
n/a
Propertypublic  $numFonts= '0'

number of fonts within the system

Default value0Details
Type
n/a
Propertypublic  $numImages= '0'

number of images being tracked within the document

Default value0Details
Type
n/a
Propertypublic  $numObj= '0'

the current number of pdf objects in the document

Default value0Details
Type
n/a
Propertypublic  $numPages= '0'

number of page objects within the document

Default value0Details
Type
n/a
Propertypublic  $objects= 'array()'

this array contains all of the pdf objects, ready for final assembly

Default valuearray()Details
Type
n/a
Propertypublic  $options= 'array( 'compression' => 1 )'

an array containing options about the document it defaults to turning on the compression of the objects

Default valuearray( 'compression' => 1 )Details
Type
n/a
Propertypublic  $procsetObjectId= ''

the object Id of the procset object

Details
Type
n/a
Propertypublic  $stack= 'array()'

object Id storage stack

Default valuearray()Details
Type
n/a
Propertypublic  $stateStack= 'array()'

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

Default valuearray()Details
Type
n/a
Propertypublic  $textStateStack= 'array( '' )'
Default valuearray( '' )Details
Type
n/a
Propertypublic  $wordSpaceAdjust= '0'

used to track the last used value of the inter-word spacing, this is so that it is known when the spacing is changed.

Default value0Details
Type
n/a

Methods

methodpublicARC4(  $text ) : void

ARC4 encrypt a text string

Parameters
Name Type Description
$text
methodpublicARC4_init(  $key = '' ) : void

initialize the ARC4 encryption

Parameters
Name Type Description
$key
methodpublicCpdf(  $pageSize = array( 0, 0, 612, 792 ) ) : void

class constructor this will start a new document

Parameters
Name Type Description
$pageSize
Details
array
array of 4 numbers, defining the bottom left and upper right corner of the page. first two are normally zero.
methodpublicPRVT_getBytes(  $data,  $pos,  $num ) : void

extract an integer from a position in a byte stream

Parameters
Name Type Description
$data
$pos
$num
Details
Access
private  
methodpublicPRVTadjustWrapText(  $text,  $actual,  $width,  $x,  $adjust,  $justification ) : void

do a part of the calculation for sorting out the justification of the text

Parameters
Name Type Description
$text
$actual
$width
$x
$adjust
$justification
Details
Access
private  
methodpublicPRVTcheckTextDirective(  $text,  $i,  $f,  $final = 0 ) : void

wrapper function for PRVTcheckTextDirective1

Parameters
Name Type Description
$text
$i
$f
$final
Details
Access
private  
methodpublicPRVTcheckTextDirective1(  $text,  $i,  $f,  $final,  $x,  $y,  $size = 0,  $angle = 0,  $wordSpaceAdjust = 0 ) : void

checks if the text stream contains a control directive if so then makes some changes and returns the number of characters involved in the directive this has been re-worked to include everything neccesary to fins the current writing point, so that the location can be sent to the callback function if required if the directive does not require a font change, then $f should be set to 0

Parameters
Name Type Description
$text
$i
$f
$final
$x
$y
$size
$angle
$wordSpaceAdjust
Details
Access
private  
methodpublicPRVTgetTextPosition(  $x,  $y,  $angle,  $size,  $wa,  $text ) : void

given a start position and information about how text is to be laid out, calculate where on the page the text will end

Parameters
Name Type Description
$x
$y
$angle
$size
$wa
$text
Details
Access
private  
methodpublicaddContent(  $content ) : void

add content to the currently active object

Parameters
Name Type Description
$content
Details
Access
private  
methodpublicaddDestination(  $label,  $style,  $a = 0,  $b = 0,  $c = 0 ) : void

create a labelled destination within the document

Parameters
Name Type Description
$label
$style
$a
$b
$c
methodpublicaddImage(  $img,  $x,  $y,  $w = 0,  $h = 0,  $quality = 75 ) : void

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

Parameters
Name Type Description
$img
$x
$y
$w
$h
$quality
methodpublicaddInfo(  $label,  $value = 0 ) : void

add content to the documents info object

Parameters
Name Type Description
$label
$value
methodpublicaddInternalLink(  $label,  $x0,  $y0,  $x1,  $y1 ) : void

add a link in the document to an internal destination (ie. within the document)

Parameters
Name Type Description
$label
$x0
$y0
$x1
$y1
methodpublicaddJpegFromFile(  $img,  $x,  $y,  $w = 0,  $h = 0 ) : void

add a JPEG image into the document, from a file

Parameters
Name Type Description
$img
$x
$y
$w
$h
methodpublicaddJpegImage_common(  $data,  $x,  $y,  $w = 0,  $h = 0,  $imageWidth,  $imageHeight,  $channels = 3 ) : void

common code used by the two JPEG adding functions

Parameters
Name Type Description
$data
$x
$y
$w
$h
$imageWidth
$imageHeight
$channels
Details
Access
private  
methodpublicaddLink(  $url,  $x0,  $y0,  $x1,  $y1 ) : void

add a link in the document to an external URL

Parameters
Name Type Description
$url
$x0
$y0
$x1
$y1
methodpublicaddMessage(  $message ) : void

used to add messages for use in debugging

Parameters
Name Type Description
$message
methodpublicaddObject(  $id,  $options = 'add' ) : void

after an object has been created, it wil only show if it has been added, using this function.

Parameters
Name Type Description
$id
$options
methodpublicaddPngFromFile(  $file,  $x,  $y,  $w = 0,  $h = 0 ) : void

add a PNG image into the document, from a file this should work with remote files

\return true if adding image succeded

Parameters
Name Type Description
$file
$x
$y
$w
$h
methodpublicaddText(  $x,  $y,  $size,  $text,  $angle = 0,  $wordSpaceAdjust = 0 ) : void

add text to the document, at a specified location, size and angle on the page

\return array( 'height' => )

Parameters
Name Type Description
$x
$y
$size
$text
$angle
$wordSpaceAdjust
methodpublicaddTextWrap(  $x,  $y,  $width,  $size,  $text,  $justification = 'left',  $angle = 0,  $test = 0 ) : void

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

return array ('text' => , 'width' => , 'height' => )

Parameters
Name Type Description
$x
$y
$width
$size
$text
$justification
$angle
$test
methodpubliccheckAllHere( ) : void

should be used for internal checks, not implemented as yet

methodpubliccloseObject( ) : void

close an object

methodpubliccompareCMYK(  $cmykArray1,  $cmykArray2 ) : void

Parameters
Name Type Description
$cmykArray1
$cmykArray2
methodpubliccurrentFont( ) : void

Get current font

\return current font name

methodpubliccurve(  $x0,  $y0,  $x1,  $y1,  $x2,  $y2,  $x3,  $y3 ) : void

draw a bezier curve based on 4 control points

Parameters
Name Type Description
$x0
$y0
$x1
$y1
$x2
$y2
$x3
$y3
methodpublicellipse(  $x0,  $y0,  $r1,  $r2 = 0,  $angle = 0,  $nSeg = 8,  $astart = 0,  $afinish = 360,  $close = 1,  $fill = 0 ) : void

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.

Parameters
Name Type Description
$x0
$y0
$r1
$r2
$angle
$nSeg
$astart
$afinish
$close
$fill
methodpublicencryptInit(  $id ) : void

initialize the encryption for processing a particular object

Parameters
Name Type Description
$id
methodpublicfilledEllipse(  $x0,  $y0,  $r1,  $r2 = 0,  $angle = 0,  $nSeg = 8,  $astart = 0,  $afinish = 360 ) : void

draw a filled ellipse

Parameters
Name Type Description
$x0
$y0
$r1
$r2
$angle
$nSeg
$astart
$afinish
methodpublicfilledRectangle(  $x1,  $y1,  $width,  $height ) : void

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

Parameters
Name Type Description
$x1
$y1
$width
$height
methodpublicfilterText(  $text ) : void

filter the text, this is applied to all text just before being inserted into the pdf document it escapes the various things that need to be escaped, and so on

Parameters
Name Type Description
$text
Details
Access
private  
methodpublicgetFirstPageId( ) : void

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.

methodpublicgetFontDecender(  $size = false ) : void

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

Parameters
Name Type Description
$size
methodpublicgetFontHeight(  $size = false ) : void

return the height in units of the current font in the given size

Parameters
Name Type Description
$size
methodpublicgetTextWidth(  $size,  $text ) : void

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

Parameters
Name Type Description
$size
$text
methodpublicline(  $x1,  $y1,  $x2,  $y2 ) : void

draw a line from one set of coordinates to another

Parameters
Name Type Description
$x1
$y1
$x2
$y2
methodpublicmd5_16(  $string ) : void

calculate the 16 byte version of the 128 bit md5 digest of the string

Parameters
Name Type Description
$string
methodpublicnewDocument(  $pageSize = array(0,0,612,792) ) : void

intialize a new document if this is called on an existing document results may be unpredictable, but the existing document would be lost at minimum this function is called automatically by the constructor function

Parameters
Name Type Description
$pageSize
Details
Access
private  
methodpublicnewPage(  $insert = 0,  $id = 0,  $pos = 'after' ) : void

add a new page to the document this also makes the new page the current active object

Parameters
Name Type Description
$insert
$id
$pos
methodpublico_action(  $id,  $action,  $options = '' ) : void

an action object, used to link to URLS initially

Parameters
Name Type Description
$id
$action
$options
methodpublico_annotation(  $id,  $action,  $options = '' ) : void

an annotation object, this will add an annotation to the current page.

initially will support just link annotations

Parameters
Name Type Description
$id
$action
$options
methodpublico_catalog(  $id,  $action,  $options = '' ) : void

define the document catalog, the overall controller for the document

Parameters
Name Type Description
$id
$action
$options
methodpublico_contents(  $id,  $action,  $options = '' ) : void

the contents objects hold all of the content which appears on pages

Parameters
Name Type Description
$id
$action
$options
methodpublico_destination(  $id,  $action,  $options = '' ) : void

destination object, used to specify the location for the user to jump to, presently on opening

Parameters
Name Type Description
$id
$action
$options
methodpublico_encryption(  $id,  $action,  $options = '' ) : void

encryption object.

Parameters
Name Type Description
$id
$action
$options
methodpublico_font(  $id,  $action,  $options = '' ) : void

an object to hold the font description

Parameters
Name Type Description
$id
$action
$options
methodpublico_fontDescriptor(  $id,  $action,  $options = '' ) : void

a font descriptor, needed for including additional fonts

Parameters
Name Type Description
$id
$action
$options
methodpublico_fontEncoding(  $id,  $action,  $options = '' ) : void

the font encoding

Parameters
Name Type Description
$id
$action
$options
methodpublico_function(  $id,  $action,  $options = '' ) : void

Add object to hold Function properties Only partial support for type 0, 3 and 4

\param object id. \param action \param options

Parameters
Name Type Description
$id
$action
$options
methodpublico_image(  $id,  $action,  $options = '' ) : void

an image object, will be an XObject in the document, includes description and data

Parameters
Name Type Description
$id
$action
$options
methodpublico_info(  $id,  $action,  $options = '' ) : void

define the document information

Parameters
Name Type Description
$id
$action
$options
methodpublico_outlines(  $id,  $action,  $options = '' ) : void

define the outlines in the doc, empty for now

Parameters
Name Type Description
$id
$action
$options
methodpublico_page(  $id,  $action,  $options = '' ) : void

a page object, it also creates a contents object to hold its contents

Parameters
Name Type Description
$id
$action
$options
methodpublico_pages(  $id,  $action,  $options = '' ) : void

object which is a parent to the pages in the document

Parameters
Name Type Description
$id
$action
$options
methodpublico_pattern(  $id,  $action,  $options = '' ) : void

Add object to hold pattern properties

\param object id. \param action \param options

\return action 'new' - dictionary name 'out' - pdf output

Parameters
Name Type Description
$id
$action
$options
methodpublico_procset(  $id,  $action,  $options = '' ) : void

the document procset, solves some problems with printing to old PS printers

Parameters
Name Type Description
$id
$action
$options
methodpublico_shading(  $id,  $action,  $options = '' ) : void

Add object to hold shading properties

\param object id. \param action \param options

\return action 'new' - dictionary name 'out' - pdf output

Parameters
Name Type Description
$id
$action
$options
methodpublico_viewerPreferences(  $id,  $action,  $options = '' ) : void

set the viewer preferences

Parameters
Name Type Description
$id
$action
$options
methodpublicopenFont(  $font ) : void

open the font file and return a php structure containing it.

first check if this one has been done before and saved in a form more suited to php note that if a php serialized version does not exist it will try and make one, but will require write access to the directory to do it... it is MUCH faster to have these serialized files.

Parameters
Name Type Description
$font
Details
Access
private  
methodpublicopenHere(  $style,  $a = 0,  $b = 0,  $c = 0 ) : void

specify where the document should open when it first starts

Parameters
Name Type Description
$style
$a
$b
$c
methodpublicopenObject( ) : void

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

methodpublicoutput(  $debug = 0 ) : void

return the pdf stream as a string returned from the function

Parameters
Name Type Description
$debug
methodpublicpartEllipse(  $x0,  $y0,  $astart,  $afinish,  $r1,  $r2 = 0,  $angle = 0,  $nSeg = 8 ) : void

draw a part of an ellipse

Parameters
Name Type Description
$x0
$y0
$astart
$afinish
$r1
$r2
$angle
$nSeg
methodpublicpolygon(  $p,  $np,  $f = 0 ) : void

draw a polygon, the syntax for this is similar to the GD polygon command

Parameters
Name Type Description
$p
$np
$f
methodpublicpopTextState( ) : void

methodpublicpushTextState(  $newState ) : void

Parameters
Name Type Description
$newState
methodpublicrectangle(  $x1,  $y1,  $width,  $height ) : void

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

Parameters
Name Type Description
$x1
$y1
$width
$height
methodpublicreopenObject(  $id ) : void

open an existing object for editing

Parameters
Name Type Description
$id
methodpublicrestoreState(  $pageEnd = 0 ) : void

restore a previously saved state

Parameters
Name Type Description
$pageEnd
methodpublicsaveState(  $pageEnd = 0 ) : void

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

Parameters
Name Type Description
$pageEnd
methodpublicselectFont(  $fontName,  $encoding = '',  $set = 1 ) : void

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.

Parameters
Name Type Description
$fontName
$encoding
$set
methodpublicsetColor(  $cmykArray,  $force = 0 ) : void

Parameters
Name Type Description
$cmykArray
$force
methodpublicsetColorRGB(  $r,  $g,  $b,  $force = 0 ) : void

sets the colour for fill operations

Parameters
Name Type Description
$r
$g
$b
$force
methodpublicsetCurrentFont( ) : void

sets up the current font, based on the font families, and the current text state note that this system is quite flexible, a font can be completely different to a font, and even will have to be defined within the family to have meaning This function is to be called whenever the currentTextState is changed, it will update the currentFont setting to whatever the appropriatte family one is.

If the user calls selectFont themselves then that will reset the currentBaseFont, and the currentFont This function will change the currentFont to whatever it should be, but will not change the currentBaseFont.

Details
Access
private  
methodpublicsetEncryption(  $userPass = '',  $ownerPass = '',  $pc = array() ) : void

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

Parameters
Name Type Description
$userPass
$ownerPass
$pc
methodpublicsetFontFamily(  $family,  $options = '' ) : void

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.

Parameters
Name Type Description
$family
$options
methodpublicsetLineStyle(  $width = 1,  $cap = '',  $join = '',  $dash = '',  $phase = 0 ) : void

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.

Parameters
Name Type Description
$width
$cap
$join
$dash
$phase
methodpublicsetPreferences(  $label,  $value = 0 ) : void

set the viewer preferences of the document, it is up to the browser to obey these.

Parameters
Name Type Description
$label
$value
methodpublicsetStrokeColor(  $cmykArray,  $force = 0 ) : void

Parameters
Name Type Description
$cmykArray
$force
methodpublicsetStrokeColorRGB(  $r,  $g,  $b,  $force = 0 ) : void

sets the colour for stroke operations

Parameters
Name Type Description
$r
$g
$b
$force
methodpublicshadedRectangle(  $x1,  $y1,  $width,  $height,  $options ) : void

Create shaded rectangle area

\param x1 \param x2 \param width \param height \param options array ( 'orientation' => <vertical|horizontal ( optianal )>, 'color0' => , 'color1' => )

Parameters
Name Type Description
$x1
$y1
$width
$height
$options
methodpublicstopObject(  $id ) : void

stop an object from appearing on pages from this point on

Parameters
Name Type Description
$id
methodpublicstream(  $options = '' ) : void

output the pdf code, streaming it to the browser the relevant headers are set so that hopefully the browser will recognise it

Parameters
Name Type Description
$options
methodpublictransaction(  $action ) : void

a few functions which should allow the document to be treated transactionally.

Parameters
Name Type Description
$action
Documentation was generated by DocBlox 0.18.1.