Class XPDF - Stefanius67/XFPDF GitHub Wiki

Full name:     \SKien\XFPDF\XPDF
Parent class:    \OPlathey\FPDF\FPDF


Extension of FPDF-Class to generate table/datagrid.

Supports:

  • Page Header/Footer including Logo
  • Colheaders
  • Totals, Subtotals, Pagetotals and Carry over
  • Use defined fonts, colors and stripped datarows
  • Specify print format with JSOn template file

Constants

Constant Description
COL_ROW_NR predifined Col-ID for automated row number
BOTTOM_MARGIN Bottom margin for trigger of the auto pagebreak
FLAG_TOTALS totals info
FLAG_TOTALS_CALC calc total for column
FLAG_TOTALS_TEXT print text in totals row
FLAG_TOTALS_EMPTY leave empty in totals row
FLAG_INT_LINK create internal link
FLAG_FORMAT special format for the cell
FLAG_CUR_SYMBOL format cell as currency with symbol
FLAG_CUR_PLAIN format cell as currency without symbol
FLAG_DATE format cell as date/time
FLAG_TIME format cell as date/time
FLAG_DATE_TIME format cell as date/time
FLAG_NUMBER format cell as number
FLAG_IBAN format cell IBAN
FLAG_ELIPSIS limit length to width with elipsis
FLAG_IMAGE cell containes image
FLAG_NO_ZERO suppress zero values
TOTALS crate totals row on the end of report
PAGE_TOTALS create totals row on each pagebreak
CARRY_OVER create carry over on the beginning of each new page
SUB_TOTALS create

Overview

Method Description
__construct class constructor.
acceptPageBreak Whenever a page break condition is met, the method is called, and the break is issued or not depending on the returned value.
addCol Add Column to the Grid.
addFont Imports a TrueType, OpenType or Type1 font and makes it available.
addLink Creates a new internal link and returns its identifier.
addPage Adds a new page to the document.
aliasNbPages Defines an alias for the total number of pages. It will be substituted as the document is closed.
bookmark Set bookmark at current position.
cell Prints a cell (rectangular area) with optional borders, background color and character string.
close Terminates the PDF document.
convText
createPDF Last step: create the document.
enableTotals Enables automatic calclation of totals.
endGrid Mark the end of the grid.
endGroup End group and print subtotals row.
error This method is automatically called in case of a fatal error.
footer Print pagefooter.
getPageBreakTrigger Get the trigger for autopagebreak
getPageHeight Get current page height.
getPageWidth Get current page width.
getStringWidth Returns the length of a string in user unit for current Font.
getX Get current x position.
getY Get current Y position.
header Print pageheader / logo / colheaders.
image Puts an image.
initGrid Initialisation of grid.
line Draws a line between two points.
link Puts a link on a rectangular area of the page.
ln Performs a line break.
multiCell This method allows printing text with line breaks.
output Send the document to a given destination: browser, file or string.
pageNo Returns the current page number.
prepare Have to be called once before datarows be added to the document.
rect Outputs a rectangle.
resetCols reset coldefinitions
row Build row.
selectDrawColor Set color for drawing.
selectFillColor Set fillcolor.
selectFont Selects given font.
selectTextColor Set color for text.
setAuthor Defines the author of the document.
setAutoPageBreak Enables or disables the automatic page breaking mode.
setColHeaderColors Set colors for text and drawing in the colheader.
setColHeaderFont Set font for col headers.
setColImageInfo Set infos for image col.
setCompression Activates or deactivates page compression.
setCreator Defines the creator of the document. This is typically the name of the application that generates the PDF.
setDateFormat Set the Date Format to use.
setDateTimeFormat Set the DateTime Format to use.
setDisplayMode Defines the way the document is to be displayed by the viewer.
setDrawColor Defines the color used for all drawing operations (lines, rectangles and cell borders).
setFillColor Defines the color used for all filling operations (filled rectangles and cell backgrounds).
setFont Sets the font used to print character strings.
setFontSize Defines the size of the current font.
setFooterColors Set colors for text and drawing in the pagefooter.
setFooterFont Set font for page footer.
setHeaderColors Set colors for text and drawing in the pageheader.
setHeaderFont Set font for page header.
setInfo Set information for document to create.
setKeywords Associates keywords with the document, generally in the form 'keyword1 keyword2 ...'.
setLeftMargin Defines the left margin.
setLineHeight Set lineheight.
setLineWidth Defines the line width.
setLink Defines the page and position a link points to.
setLocale Set locale for formating.
setLogo Set logo printed in the document header.
setLogoHeight Set height of the logo in the document header.
setMargins Defines the left, top and right margins.
setNumberFormat Set format for numbers.
setPageFooter Set the pagefooter of the document.
setPageHeader Set the pageheader of the document.
setPageSubject Set the subject in the pageheader of the document.
setRightMargin Defines the right margin.
setRowColors Set colors for text and drawing in the grid.
setRowFont Set font for data rows.
setSubHeaderFont Set font for sub headers.
setSubject Defines the subject of the document.
setSubjectFont Set font for subject in the page header.
setTextColor Defines the color used for text.
setTimeFormat Set the Time Format to use.
setTitle Defines the title of the document.
setTopMargin Defines the top margin.
setTotalsText Set text for totals, subtotals and carry over row.
setX Set new X position.
setXY Set new X and Y position.
setY Set new Y position and optionally moves the current X-position back to the left margin.
startGroup Starts group for new subtotals.
text Prints a character string.
write This method prints text from the current position.

Methods

__construct

class constructor.

public XPDF::__construct(string $orientation = 'P', string $unit = 'mm', string|array $size = 'A4')

allows to set up the page size, the orientation and the unit of measure used in all methods (except for font sizes).

Parameters:

Parameter Type Description
orientation string
unit string
size string | array

See Also:

[go to top]


addCol

Add Column to the Grid.

public XPDF::addCol(string $strColHeader, float $fltWidth, string $strAlign, string|int $strField, int $wFlags) : int

String is directly mapped to field in datarow, number is requested through Col() method

Parameters:

Parameter Type Description
strColHeader string title text in the header, if equal -1, colspan of previous col ist increased
fltWidth float width in mm (if -1, col is enhanced so table uses on full page width)
strAlign string alignment of datacol 'L', 'C' or 'R' - headerer cells allways centered
strField string | int data-field or Column ID.
wFlags int Flags to define behaviour for column

Return Type: int

Index of the inserted col

[go to top]


convText

public XPDF::convText(string $strText) : string

Parameters:

Parameter Type Description
strText string

Return Type: string

[go to top]


createPDF

Last step: create the document.

public XPDF::createPDF(string $strFilename = '') : void

If nor filename is given, the title set with SetInfo() or SetTitle() method is used (or 'XFPDF.pdf' if no title set so far). If the filename not ending with .pdf (case insensitive), the extension ist appended.

Parameters:

Parameter Type Description
strFilename string Filename

[go to top]


enableTotals

Enables automatic calclation of totals.

public XPDF::enableTotals(int $iTotals = self::TOTALS) : void
  • totals over all at end of grid (self::TOTALS)
  • subtotals at end of each page (self::PAGE_TOTALS)
  • carry over at beginning of new page (self::CARRY_OVER)
!! Can be controled/overwritten through JSON-Format in InitGrid() !!

Parameters:

Parameter Type Description
iTotals int combination of

See Also:

[go to top]


endGrid

Mark the end of the grid.

public XPDF::endGrid() : void

If totals enabled, total row will be printed.

[go to top]


endGroup

End group and print subtotals row.

public XPDF::endGroup() : void

[go to top]


footer

Print pagefooter.

public XPDF::footer() : void

{@inheritDoc}

See Also:

[go to top]


header

Print pageheader / logo / colheaders.

public XPDF::header() : void

{@inheritDoc}

See Also:

[go to top]


initGrid

Initialisation of grid.

public XPDF::initGrid(string $strFilename) : void
  • fonts
  • colors
  • totals/subtotals/carry over text
  • charset
  • formating
See xfpdf-sample.json for more information about this file.

Parameters:

Parameter Type Description
strFilename string

[go to top]


prepare

Have to be called once before datarows be added to the document.

public XPDF::prepare() : void

[go to top]


resetCols

reset coldefinitions

public XPDF::resetCols() : void

[go to top]


row

Build row.

public XPDF::row(array $row) : void

If fieldname specified in AddCol(), directly the value from the associative array is inserted (in case of DATE-Field value is formated d.m.Y) all other columns are requested through GetCol() - method

Parameters:

Parameter Type Description
row array current row as associative array (may comes from DB query)

[go to top]


selectDrawColor

Set color for drawing.

public XPDF::selectDrawColor(string $strColor) : void

Parameters:

Parameter Type Description
strColor string color to select in HTML-Format #RRGGBB

[go to top]


selectFillColor

Set fillcolor.

public XPDF::selectFillColor(string $strColor) : void

Parameters:

Parameter Type Description
strColor string color to select in HTML-Format #RRGGBB

[go to top]


selectFont

Selects given font.

public XPDF::selectFont(\SKien\XFPDF\XPDFFont $font) : void

Parameters:

Parameter Type Description
font \SKien\XFPDF\XPDFFont

[go to top]


selectTextColor

Set color for text.

public XPDF::selectTextColor(string $strColor) : void

Parameters:

Parameter Type Description
strColor string color to select in HTML-Format #RRGGBB

[go to top]


setColHeaderColors

Set colors for text and drawing in the colheader.

public XPDF::setColHeaderColors(string $strTextColor, string $strFillColor) : void

!! Can be controled/overwritten through JSON-Format in InitGrid() !!

Parameters:

Parameter Type Description
strTextColor string
strFillColor string

See Also:

[go to top]


setColHeaderFont

Set font for col headers.

public XPDF::setColHeaderFont(string $strFontname, string $strStyle, int $iSize) : void

!! Can be controled/overwritten through JSON-Format in InitGrid() !!

Parameters:

Parameter Type Description
strFontname string
strStyle string
iSize int

See Also:

[go to top]


setColImageInfo

Set infos for image col.

public XPDF::setColImageInfo(int $iCol, float $fltTop, float $fltLeft, float $fltHeight = -1, float $fltWidth = -1) : void

Set the margin from the top left corner of the cell and the height/width of the image.

  • If no height and width specified, the image is printed in its origin size
  • If only one of both is specified, the image is scaled and the aspect ratio is retained

Parameters:

Parameter Type Description
iCol int index of the col (usually the return value of the AddCol() Method)
fltTop float top margin from row in user units
fltLeft float left margin from cell in user units
fltHeight float height of the image in user units
fltWidth float width of the image in user units

[go to top]


setDateFormat

Set the Date Format to use.

public XPDF::setDateFormat(int|string $format) : void

Date values are formatet using the language set by setLocale().

The $format parameter can either be one of the IntlDateFormatter int Constants

const en_US de_DE
IntlDateFormatter::SHORT M/d/yy dd.MM.yy
IntlDateFormatter::MEDIUM MMM d, yyyy dd.MM.yyyy
IntlDateFormatter::LONG MMMM d, yyyy dd. MMMM yyyy
IntlDateFormatter::FULL EEEE, MMMM d, yyyy EEEE dd. MMMM yyyy

or a string pattern following the definition of IntlDateFormatter (see link below)

Pattern to Format Date and Time

Note: This property can also be set in the JSON file used in initGrid() !!

Parameters:

Parameter Type Description
format int | string

See Also:

[go to top]


setDateTimeFormat

Set the DateTime Format to use.

public XPDF::setDateTimeFormat(int|string $formatD, int $formatT) : void

You can either set the $formatD and $formatT parameter to one of the IntlDateFormatter int Constants (see setDateFormat, setTimeFormat) or set a string pattern following the definition of IntlDateFormatter as first parameter (see link below).

Note: This property can also be set in the JSON file used in initGrid() !!

Parameters:

Parameter Type Description
formatD int | string
formatT int

See Also:

[go to top]


setFooterColors

Set colors for text and drawing in the pagefooter.

public XPDF::setFooterColors(string $strTextColor, string $strDrawColor) : void

!! Can be controled/overwritten through JSON-Format in InitGrid() !!

Parameters:

Parameter Type Description
strTextColor string
strDrawColor string

See Also:

[go to top]


setFooterFont

Set font for page footer.

public XPDF::setFooterFont(string $strFontname, string $strStyle, int $iSize) : void

!! Can be controled/overwritten through JSON-Format in InitGrid() !!

Parameters:

Parameter Type Description
strFontname string
strStyle string
iSize int

See Also:

[go to top]


setHeaderColors

Set colors for text and drawing in the pageheader.

public XPDF::setHeaderColors(string $strTextColor, string $strDrawColor) : void

!! Can be controled/overwritten through JSON-Format in InitGrid() !!

Parameters:

Parameter Type Description
strTextColor string
strDrawColor string

See Also:

[go to top]


setHeaderFont

Set font for page header.

public XPDF::setHeaderFont(string $strFontname, string $strStyle, int $iSize) : void

!! Can be controled/overwritten through JSON-Format in InitGrid() !!

Parameters:

Parameter Type Description
strFontname string
strStyle string
iSize int

See Also:

[go to top]


setInfo

Set information for document to create.

public XPDF::setInfo(string $strTitle, string $strSubject = '', string $strAuthor = '', string $strKeywords = '', bool $isUTF8 = true) : void

Parameters:

Parameter Type Description
strTitle string
strSubject string
strAuthor string
strKeywords string
isUTF8 bool Indicates if the strings encoded in ISO-8859-1 (false) or UTF-8 (true). (Default: true)

[go to top]


setLineHeight

Set lineheight.

public XPDF::setLineHeight(float $fltLineHeight) : void

!! Can be controled/overwritten through JSON-Format in InitGrid() !!

Parameters:

Parameter Type Description
fltLineHeight float lineheight in mm

See Also:

[go to top]


setLocale

Set locale for formating.

public XPDF::setLocale(string $strLocale) : void

If $strLocale is an comma separated list each value is tried to be set as new locale until success.
Example: "de_DE.utf8, de_DE, de, DE"

!! Can be controled/overwritten through JSON-Format in InitGrid() !!

Parameters:

Parameter Type Description
strLocale string

See Also:

[go to top]


setLogo

Set logo printed in the document header.

public XPDF::setLogo(string $strLogo) : void

The logo is printed right-aligned in the header, and by default, the logo will be scaled to a height of 8mm. Another height can be set with XPDF::setLogoHeight().
For convinience, the loge can be set directly within XPDF::setPageHeader().

Parameters:

Parameter Type Description
strLogo string image file to print.

See Also:

[go to top]


setLogoHeight

Set height of the logo in the document header.

public XPDF::setLogoHeight(float $fltLogoHeight) : void

Parameters:

Parameter Type Description
fltLogoHeight float height of the logo image

[go to top]


setNumberFormat

Set format for numbers.

public XPDF::setNumberFormat(int $iDecimals, string $strPrefix = '', string $strSuffix = '') : void

Decimal point and thousands separator from locale settings is used if available.

!! Can be controled/overwritten through JSON-Format in InitGrid() !!

Parameters:

Parameter Type Description
iDecimals int
strPrefix string
strSuffix string

See Also:

[go to top]


setPageFooter

Set the pagefooter of the document.

public XPDF::setPageFooter(string $strFooter) : void

Parameters:

Parameter Type Description
strFooter string The footer can consist of up to three sections delimitet by TAB ('\t')
possible placeholders are
  • '{D}' -> current date (DD.MM.YYYY)
  • '{T}' -> current time (HH:ii)
  • '{PN}' -> pagenumber
  • '{NP}' -> total number of pages
default footer is: 'Page {PN}/{NP}\t{D} {T}'

[go to top]


setPageHeader

Set the pageheader of the document.

public XPDF::setPageHeader(string $strTitle, string $strHeaderSubject = '', string $strLogo = '') : void

The title is printed in the left of the pageheader using the font set with XPDF:SetHeaderFont()
Optional the subject and/or the logo can be set. Subject and logo can also be set using XPDF:SetSubject() and XPDF:SetLogo()
The page header is separated from the report by a double line.

Parameters:

Parameter Type Description
strTitle string Title of the Report
strHeaderSubject string Subject of the Report
strLogo string Logo to print.

See Also:

[go to top]


setPageSubject

Set the subject in the pageheader of the document.

public XPDF::setPageSubject(string $strPageSubject) : void

The subject is printed in the left of the pageheader in the 2'nd line using the font set with XPDF:SetSubjectFont()

Parameters:

Parameter Type Description
strPageSubject string

See Also:

[go to top]


setRowColors

Set colors for text and drawing in the grid.

public XPDF::setRowColors(string $strTextColor, string $strDrawColor, string $strFillColor, bool $bStripped = true) : void

!! Can be controled/overwritten through JSON-Format in InitGrid() !!

Parameters:

Parameter Type Description
strTextColor string
strDrawColor string
strFillColor string
bStripped bool

See Also:

[go to top]


setRowFont

Set font for data rows.

public XPDF::setRowFont(string $strFontname, string $strStyle, int $iSize) : void

!! Can be controled/overwritten through JSON-Format in InitGrid() !!

Parameters:

Parameter Type Description
strFontname string
strStyle string
iSize int

See Also:

[go to top]


setSubHeaderFont

Set font for sub headers.

public XPDF::setSubHeaderFont(string $strFontname, string $strStyle, int $iSize) : void

!! Can be controled/overwritten through JSON-Format in InitGrid() !!

Parameters:

Parameter Type Description
strFontname string
strStyle string
iSize int

See Also:

[go to top]


setSubjectFont

Set font for subject in the page header.

public XPDF::setSubjectFont(string $strFontname, string $strStyle, int $iSize) : void

!! Can be controled/overwritten through JSON-Format in InitGrid() !!

Parameters:

Parameter Type Description
strFontname string
strStyle string
iSize int

See Also:

[go to top]


setTimeFormat

Set the Time Format to use.

public XPDF::setTimeFormat(int|string $format) : void

The $format parameter can either be one of the IntlDateFormatter int Constants

const en_US de_DE
IntlDateFormatter::SHORT KK:mm a HH:mm
IntlDateFormatter::MEDIUM KK:mm:ss a HH:mm:ss
IntlDateFormatter::LONG KK:mm:ss a o HH:mm:ss o
IntlDateFormatter::FULL KK:mm:ss a vvvv HH:mm:ss vvvv

or a string pattern following the definition of IntlDateFormatter (see link below)

Note: This property can also be set in the JSON file used in initGrid() !!

Parameters:

Parameter Type Description
format int | string

See Also:

[go to top]


setTotalsText

Set text for totals, subtotals and carry over row.

public XPDF::setTotalsText(string $strTotals, string $strPageTotals = '', string $strCarryOver = '') : void

Following placeholders will be replaced:

  • {PN} -> current page
  • {PN-1} -> previous page
!! Can be controled/overwritten through JSON-Format in InitGrid() !!

Parameters:

Parameter Type Description
strTotals string
strPageTotals string
strCarryOver string

See Also:

[go to top]


startGroup

Starts group for new subtotals.

public XPDF::startGroup(string $strTotals, string $strHeader = null) : void

Reset calculated subtotals and print subheader if strHeader is set

Parameters:

Parameter Type Description
strTotals string
strHeader string

[go to top]


Inherited methods

acceptPageBreak

Whenever a page break condition is met, the method is called, and the break is issued or not depending on the returned value.

public FPDF::acceptPageBreak() : bool

The default implementation returns a value according to the mode selected by SetAutoPageBreak(). This method is called automatically and should not be called directly by the application.

For usage in derived classes see example at http://www.fpdf.org/en/doc/acceptpagebreak.htm.

Return Type: bool

See Also:

[go to top]


addFont

Imports a TrueType, OpenType or Type1 font and makes it available.

public FPDF::addFont(string $family, string $style = '', string $file = '') : void

It is necessary to generate a font definition file first with the MakeFont utility. The definition file (and the font file itself when embedding) must be present in the font directory. If it is not found, the error "Could not include font definition file" is raised.

Parameters:

Parameter Type Description
family string Font family. The name can be chosen arbitrarily. If it is a standard family name, it will override the corresponding font.
style string Font style.
Possible values are (case insensitive):
  • empty string: regular
  • 'B': bold
  • 'I': italic
  • 'BI' or 'IB': bold italic
The default value is regular.
file string The font definition file.
By default, the name is built from the family and style, in lower case with no space.

[go to top]


addLink

Creates a new internal link and returns its identifier.

public FPDF::addLink() : int

An internal link is a clickable area which directs to another place within the document. The identifier can then be passed to Cell(), Write(), Image() or Link(). The destination is defined with SetLink().

Return Type: int

[go to top]


addPage

Adds a new page to the document.

public FPDF::addPage(string $orientation = '', string|array $size = '', int $rotation) : void

If a page is already present, the Footer() method is called first to output the footer. Then the page is added, the current position set to the top-left corner according to the left and top margins, and Header() is called to display the header. The font which was set before calling is automatically restored. There is no need to call SetFont() again if you want to continue with the same font. The same is true for colors and line width. The origin of the Y-position system is at the top-left corner and increasing Y-positions go downwards.

Parameters:

Parameter Type Description
orientation string Default page orientation.
Possible values are (case insensitive):
  • 'P' or 'Portrait'
  • 'L' or 'Landscape'
Default value is 'P'.
size string | array The size used for pages.
It can be either one of the following values (case insensitive):
  • 'A3'
  • 'A4'
  • 'A5'
  • 'Letter'
  • 'Legal'
or an array containing the width and the height (expressed in the unit given by unit).
Default value is 'A4'.
rotation int Angle by which to rotate the page.
It must be a multiple of 90; positive values mean clockwise rotation. The default value is 0.

[go to top]


aliasNbPages

Defines an alias for the total number of pages. It will be substituted as the document is closed.

public FPDF::aliasNbPages(string $alias = '{nb}') : void

Parameters:

Parameter Type Description
alias string The alias. Default value: {nb}.

[go to top]


bookmark

Set bookmark at current position.

public FPDF::bookmark(string $txt, bool $isUTF8 = true, int $level, int $y) : void

from FPDF.org extension to create Bookmarks

Parameters:

Parameter Type Description
txt string
isUTF8 bool
level int
y int

[go to top]


cell

Prints a cell (rectangular area) with optional borders, background color and character string.

public FPDF::cell(float $w, float $h, string $txt = '', int|string $border, float $ln, string $align = '', bool $fill = false, string|int $link = '') : void

The upper-left corner of the cell corresponds to the current position. The text can be aligned or centered. After the call, the current position moves to the right or to the next line. It is possible to put a link on the text. If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.

Parameters:

Parameter Type Description
w float Cell width. If 0, the cell extends up to the right margin.
h float Cell height. Default value: 0.
txt string String to print. Default value: empty string.
border int | string Indicates if borders must be drawn around the cell.
The value can be either a number:
  • 0: no border
  • 1: frame
or a string containing some or all of the following characters (in any order):
  • 'L': left
  • 'T': top
  • 'R': right
  • 'B': bottom
Default value: 0.
ln float Indicates where the current position should go after the call.
Possible values are:
  • 0: to the right
  • 1: to the beginning of the next line
  • 2: below
Putting 1 is equivalent to putting 0 and calling Ln() just after.
Default value: 0.
align string Allows to center or align the text.
Possible values are:
  • 'L' or empty string: left align (default value)
  • 'C': center
  • 'R': right align
fill bool Indicates if the cell background must be painted (true) or transparent (false).
If set to true, current FillColor is used for the background.
Default value: false.
link string | int URL or identifier for internal link created by AddLink().

[go to top]


close

Terminates the PDF document.

public FPDF::close() : void

It is not necessary to call this method explicitly because Output() does it automatically. If the document contains no page, AddPage() is called to prevent from getting an invalid document.

[go to top]


error

This method is automatically called in case of a fatal error.

public FPDF::error(string $msg) : void

It simply throws an exception with the provided message. An inherited class may override it to customize the error handling but the method should never return, otherwise the resulting document would probably be invalid.

Parameters:

Parameter Type Description
msg string The error message.

[go to top]


footer

This method is used to render the page footer.

public FPDF::footer() : void

It is automatically called by AddPage() and Close() and should not be called directly by the application. The implementation in FPDF is empty, so you have to subclass it and override the method if you want a specific processing.

[go to top]


getPageBreakTrigger

Get the trigger for autopagebreak

public FPDF::getPageBreakTrigger() : float

Return Type: float

[go to top]


getPageHeight

Get current page height.

public FPDF::getPageHeight() : float

Return Type: float

[go to top]


getPageWidth

Get current page width.

public FPDF::getPageWidth() : float

Return Type: float

[go to top]


getStringWidth

Returns the length of a string in user unit for current Font.

public FPDF::getStringWidth(string $s) : float

A font must be selected.

Parameters:

Parameter Type Description
s string The string whose length is to be computed.

Return Type: float

[go to top]


getX

Get current x position.

public FPDF::getX() : float

Return Type: float

[go to top]


getY

Get current Y position.

public FPDF::getY() : float

Return Type: float

[go to top]


header

This method is used to render the page header.

public FPDF::header() : void

It is automatically called by AddPage() and should not be called directly by the application. The implementation in FPDF is empty, so you have to subclass it and override the method if you want a specific processing.

[go to top]


image

Puts an image.

public FPDF::image(string $file, float $x = null, float $y = null, float $w, float $h, string $type = '', string|int $link = '') : void

The size it will take on the page can be specified in different ways:

  • explicit width and height (expressed in user unit or dpi)
  • one explicit dimension, the other being calculated automatically in order to keep the original proportions
  • no explicit dimension, in which case the image is put at 96 dpi
Supported formats are JPEG, PNG and GIF. The GD extension is required for GIF.
For JPEGs, all flavors are allowed:
  • gray scales
  • true colors (24 bits)
  • CMYK (32 bits)
For PNGs, are allowed:
  • gray scales on at most 8 bits (256 levels)
  • indexed colors
  • true colors (24 bits)
For GIFs: in case of an animated GIF, only the first frame is displayed.

Transparency is supported.

The format can be specified explicitly or inferred from the file extension.

It is possible to put a link on the image.

Remark: if an image is used several times, only one copy is embedded in the file.

Parameters:

Parameter Type Description
file string Path or URL of the image.
x float X-position of the upper-left corner.

If not specified or equal to null, the current X-position is used.
y float Y-position of the upper-left corner.
If not specified or equal to null, the current Y-position is used;
moreover, a page break is triggered first if necessary (in case automatic page breaking is enabled) and,
after the call, the current Y-position is moved to the bottom of the image.
w float Width of the image in the page.
There are three cases:
  • If the value is positive, it represents the width in user unit
  • If the value is negative, the absolute value represents the horizontal resolution in dpi
  • If the value is not specified or equal to zero, it is automatically calculated
    h float Height of the image in the page.
    There are three cases:
    • If the value is positive, it represents the height in user unit
    • If the value is negative, the absolute value represents the vertical resolution in dpi
    • If the value is not specified or equal to zero, it is automatically calculated
      type string Image format.
      Possible values are (case insensitive):
      • JPG
      • JPEG
      • PNG
      • GIF
      If not specified, the type is inferred from the file extension.
      link string | int URL or identifier for internal link created by AddLink().

      [go to top]


      line

      Draws a line between two points.

      public FPDF::line(float $x1, float $y1, float $x2, float $y2) : void

      The X/Y-positions refer to the top left corner of the page. Set margins are NOT taken into account.

      Parameters:

      Parameter Type Description
      x1 float X-position upper left corner
      y1 float Y-position upper left corner
      x2 float X-position lower right corner
      y2 float Y-position lower right corner

      [go to top]


      link

      Puts a link on a rectangular area of the page.

      public FPDF::link(float $x, float $y, float $w, float $h, string|int $link) : void

      Text or image links are generally put via Cell(), Write() or Image(), but this method can be useful for instance to define a clickable area inside an image. Target can be an external URL or an internal link ID created and specified by AddLink()/SetLink()

      Parameters:

      Parameter Type Description
      x float X-position
      y float Y-position
      w float Width
      h float Height
      link string | int URL or link-ID

      [go to top]


      ln

      Performs a line break.

      public FPDF::ln(float $h = null) : void

      The current X-position goes back to the left margin and the Y-position increases by the amount passed in parameter.

      Parameters:

      Parameter Type Description
      h float The height of the break.
      By default, the value equals the height of the last printed cell.

      [go to top]


      multiCell

      This method allows printing text with line breaks.

      public FPDF::multiCell(float $w, float $h, string $txt, int|string $border, string $align = 'J', bool $fill = false) : void

      They can be automatic (as soon as the text reaches the right border of the cell) or explicit (via the \n character). As many cells as necessary are output, one below the other. Text can be aligned, centered or justified. The cell block can be framed and the background painted.

      Parameters:

      Parameter Type Description
      w float Cell width. If 0, the cell extends up to the right margin.
      h float Cell height. Default value: 0.
      txt string String to print. Default value: empty string.
      border int | string Indicates if borders must be drawn around the cell.
      The value can be either a number:
      • 0: no border
      • 1: frame
      or a string containing some or all of the following characters (in any order):
      • 'L': left
      • 'T': top
      • 'R': right
      • 'B': bottom
      Default value: 0.
      align string Allows to center or align the text.
      Possible values are:
      • 'L' or empty string: left align (default value)
      • 'C': center
      • 'R': right align
      fill bool Indicates if the cell background must be painted (true) or transparent (false).
      If set to true, current FillColor is used for the background.
      Default value: false.

      [go to top]


      output

      Send the document to a given destination: browser, file or string.

      public FPDF::output(string $dest = '', string $name = '', bool $isUTF8 = true) : string

      In the case of a browser, the PDF viewer may be used or a download may be forced. The method first calls Close() if necessary to terminate the document.

      Parameters:

      Parameter Type Description
      dest string Destination where to send the document.
      It can be one of the following:
      • 'I': send the file inline to the browser. The PDF viewer is used if available.
      • 'D': send to the browser and force a file download with the name given by name.
      • 'F': save to a local file with the name given by name (may include a path).
      • 'S': return the document as a string.
      The default value is I.
      name string The name of the file. It is ignored in case of destination 'S'.
      The default value is doc.pdf.
      isUTF8 bool Indicates if name is encoded in ISO-8859-1 (false) or UTF-8 (true).
      Only used for destinations I and D.
      The default value is true.

      Return Type: string

      [go to top]


      pageNo

      Returns the current page number.

      public FPDF::pageNo() : int

      Return Type: int

      [go to top]


      rect

      Outputs a rectangle.

      public FPDF::rect(float $x, float $y, float $w, float $h, string $style = '') : void

      It can be drawn (border only), filled (with no border) or both. The X/Y-position refer to the top left corner of the page. Set margins are NOT taken into account.

      Parameters:

      Parameter Type Description
      x float X-position upper left corner
      y float Y-position upper left corner
      w float Width
      h float Height
      style string Style of rendering.
      Possible values are:
      • 'D' or empty string: draw the shape. This is the default value.
      • 'F': fill.
      • 'DF' or 'FD': draw the shape and fill.

      [go to top]


      setAuthor

      Defines the author of the document.

      public FPDF::setAuthor(string $author, bool $isUTF8 = true) : void

      Parameters:

      Parameter Type Description
      author string
      isUTF8 bool Indicates if the string is encoded in ISO-8859-1 (false) or UTF-8 (true). Default value: true.

      [go to top]


      setAutoPageBreak

      Enables or disables the automatic page breaking mode.

      public FPDF::setAutoPageBreak(bool $auto, float $margin) : void

      When enabling, the second parameter is the distance from the bottom of the page that defines the triggering limit. By default, the mode is on and the margin is 2 cm.

      Parameters:

      Parameter Type Description
      auto bool indicating if mode should be on or off.
      margin float Distance from the bottom of the page.

      [go to top]


      setCompression

      Activates or deactivates page compression.

      public FPDF::setCompression(bool $compress) : void

      When activated, the internal representation of each page is compressed, which leads to a compression ratio of about 2 for the resulting document. Compression is on by default.

      Note: the Zlib extension is required for this feature. If not present, compression will be turned off.

      Parameters:

      Parameter Type Description
      compress bool

      [go to top]


      setCreator

      Defines the creator of the document. This is typically the name of the application that generates the PDF.

      public FPDF::setCreator(string $creator, bool $isUTF8 = true) : void

      Parameters:

      Parameter Type Description
      creator string
      isUTF8 bool Indicates if the string is encoded in ISO-8859-1 (false) or UTF-8 (true). Default value: true.

      [go to top]


      setDisplayMode

      Defines the way the document is to be displayed by the viewer.

      public FPDF::setDisplayMode(string|float $zoom, string $layout = 'default') : void

      The zoom level can be set:
      pages can be displayed

      • entirely on screen
      • occupy the full width of the window
      • use real size
      • be scaled by a specific zooming factor
      • or use viewer default (configured in the Preferences menu of Adobe Reader).
      The page layout can be specified too:
      • single at once
      • continuous display
      • two columns
      • or viewer default.
      Note: this settings are ignored when displaying the PDF inside of a browser!

      Parameters:

      Parameter Type Description
      zoom string | float The zoom to use.
      It can be one of the following string values:
      • 'fullpage': displays the entire page on screen
      • 'fullwidth': uses maximum width of window
      • 'real': uses real size (equivalent to 100% zoom)
      • 'default': uses viewer default mode
      • or a number indicating the zooming factor to use.
      layout string The page layout. Possible values are:
      • 'single': displays one page at once
      • 'continuous': displays pages continuously
      • 'two': displays two pages on two columns
      • 'defaul't: uses viewer default mode
      Default value is default.

      [go to top]


      setDrawColor

      Defines the color used for all drawing operations (lines, rectangles and cell borders).

      public FPDF::setDrawColor(int $r, int $g = null, int $b = null) : void

      It can be expressed in RGB components or gray scale. The method can be called before the first page is created and the value is retained from page to page.

      Parameters:

      Parameter Type Description
      r int If g and b are given, red component; if not, indicates the gray level. Value between 0 and 255.
      g int Green component (between 0 and 255).
      b int Blue component (between 0 and 255).

      [go to top]


      setFillColor

      Defines the color used for all filling operations (filled rectangles and cell backgrounds).

      public FPDF::setFillColor(int $r, int $g = null, int $b = null) : void

      It can be expressed in RGB components or gray scale. The method can be called before the first page is created and the value is retained from page to page.

      Parameters:

      Parameter Type Description
      r int If g and b are given, red component; if not, indicates the gray level. Value between 0 and 255.
      g int Green component (between 0 and 255).
      b int Blue component (between 0 and 255).

      [go to top]


      setFont

      Sets the font used to print character strings.

      public FPDF::setFont(string $family, string $style = '', float $size) : void

      It is mandatory to call this method at least once before printing text or the resulting document would not be valid. The font can be either a standard one or a font added via the AddFont() method. Standard fonts use the Windows encoding cp1252 (Western Europe). The method can be called before the first page is created and the font is kept from page to page. If you just wish to change the current font size, it is simpler to call SetFontSize().

      Note:
      the font definition files must be accessible. They are searched successively in:

      • The directory defined by the FPDF_FONTPATH constant (if this constant is defined)
      • The 'font' directory located in the same directory as fpdf.php (if it exists)
      • The directories accessible through include()

      Parameters:

      Parameter Type Description
      family string Family font.
      It can be either a name defined by AddFont() or one of the standard families (case insensitive):
      • 'Courier' (fixed-width)
      • 'Helvetica' or 'Arial' (synonymous; sans serif)
      • 'Times' (serif)
      • 'Symbol' (symbolic)
      • 'ZapfDingbats' (symbolic)
      It is also possible to pass an empty string. In that case, the current family is kept.
      style string Font style.
      ossible values are (case insensitive):
      • empty string: regular
      • 'B': bold
      • 'I': italic
      • 'U': underline
      • or any combination.
      The default value is regular. Bold and italic styles do not apply to Symbol and ZapfDingbats.
      size float Font size in points.
      The default value is the current size.
      If no size has been specified since the beginning of the document, the value taken is 12.

      [go to top]


      setFontSize

      Defines the size of the current font.

      public FPDF::setFontSize(float $size) : void

      Parameters:

      Parameter Type Description
      size float The size (in points).

      [go to top]


      setKeywords

      Associates keywords with the document, generally in the form 'keyword1 keyword2 ...'.

      public FPDF::setKeywords(string $keywords, bool $isUTF8 = true) : void

      Parameters:

      Parameter Type Description
      keywords string
      isUTF8 bool Indicates if the string is encoded in ISO-8859-1 (false) or UTF-8 (true). Default value: true.

      [go to top]


      setLeftMargin

      Defines the left margin.

      public FPDF::setLeftMargin(float $margin) : void

      The method can be called before creating the first page. If the current X-position gets out of page, it is brought back to the margin.

      Parameters:

      Parameter Type Description
      margin float Left margin.

      [go to top]


      setLineWidth

      Defines the line width.

      public FPDF::setLineWidth(float $width) : void

      By default, the value equals 0.2 mm. The method can be called before the first page is created and the value is retained from page to page.

      Parameters:

      Parameter Type Description
      width float

      [go to top]


      setLink

      Defines the page and position a link points to.

      public FPDF::setLink(int $link, float $y, int $page = -1) : void

      Parameters:

      Parameter Type Description
      link int The link identifier created by AddLink().
      y float Y-position of target position; -1 indicates the current position. The default value is 0 (top of page).
      page int Number of target page; -1 indicates the current page. This is the default value.

      [go to top]


      setMargins

      Defines the left, top and right margins.

      public FPDF::setMargins(float $left, float $top, float $right = null) : void

      By default, they equal 1 cm. Call this method to change them.

      Parameters:

      Parameter Type Description
      left float Left margin.
      top float Top margin.
      right float Right margin. Default value is the left one.

      [go to top]


      setRightMargin

      Defines the right margin.

      public FPDF::setRightMargin(float $margin) : void

      The method can be called before creating the first page.

      Parameters:

      Parameter Type Description
      margin float

      [go to top]


      setSubject

      Defines the subject of the document.

      public FPDF::setSubject(string $subject, bool $isUTF8 = true) : void

      Parameters:

      Parameter Type Description
      subject string
      isUTF8 bool Indicates if the string is encoded in ISO-8859-1 (false) or UTF-8 (true). Default value: true.

      [go to top]


      setTextColor

      Defines the color used for text.

      public FPDF::setTextColor(int $r, int $g = null, int $b = null) : void

      It can be expressed in RGB components or gray scale. The method can be called before the first page is created and the value is retained from page to page.

      Parameters:

      Parameter Type Description
      r int If g and b are given, red component; if not, indicates the gray level. Value between 0 and 255.
      g int Green component (between 0 and 255).
      b int Blue component (between 0 and 255).

      [go to top]


      setTitle

      Defines the title of the document.

      public FPDF::setTitle(string $title, bool $isUTF8 = true) : void

      Parameters:

      Parameter Type Description
      title string The title.
      isUTF8 bool Indicates if the string is encoded in ISO-8859-1 (false) or UTF-8 (true). Default value: true.

      [go to top]


      setTopMargin

      Defines the top margin.

      public FPDF::setTopMargin(float $margin) : void

      The method can be called before creating the first page.

      Parameters:

      Parameter Type Description
      margin float

      [go to top]


      setX

      Set new X position.

      public FPDF::setX(float $x) : void

      If the passed value is negative, it is relative to the right of the page.

      Parameters:

      Parameter Type Description
      x float

      [go to top]


      setXY

      Set new X and Y position.

      public FPDF::setXY(float $x, float $y) : void

      If the passed values are negative, they are relative respectively to the right and bottom of the page.

      Parameters:

      Parameter Type Description
      x float
      y float

      [go to top]


      setY

      Set new Y position and optionally moves the current X-position back to the left margin.

      public FPDF::setY(float $y, bool $resetX = true) : void

      If the passed value is negative, it is relative to the bottom of the page.

      Parameters:

      Parameter Type Description
      y float
      resetX bool

      [go to top]


      text

      Prints a character string.

      public FPDF::text(float $x, float $y, string $txt) : void

      The origin is on the left of the first character, on the baseline. This method allows to place a string precisely on the page, but it is usually easier to use Cell(), MultiCell() or Write() which are the standard methods to print text.

      Parameters:

      Parameter Type Description
      x float X-position
      y float Y-position
      txt string String to print.

      [go to top]


      write

      This method prints text from the current position.

      public FPDF::write(float $h, string $txt, string|int $link = '') : void

      When the right margin is reached (or the \n character is met) a line break occurs and text continues from the left margin. Upon method exit, the current position is left just at the end of the text. It is possible to put a link on the text.

      Parameters:

      Parameter Type Description
      h float Line height.
      txt string String to print.
      link string | int URL or identifier for internal link created by AddLink().

      [go to top]


      ⚠️ **GitHub.com Fallback** ⚠️