Documentation

Horde_Pdf_Writer
in package

The Horde_Pdf_Writer class provides a PHP-only implementation of a PDF library. No external libs or PHP extensions are required.

Tags
category

Horde

Table of Contents

$fh  : float
Current height of page format in user units.
$fhPt  : float
Current height of page format in points.
$fw  : float
Current width of page format in user units.
$fwPt  : float
Current width of page format in points.
$h  : float
Current height of page in user units
$hPt  : float
Current height of page in points.
$w  : float
Current width of page in user units
$wPt  : float
Current width of page in points.
$x  : float
The current horizontal position for cell positioning.
$y  : float
The current vertical position for cell positioning.
$_alias_nb_pages  : string
Alias for total number of pages.
$_auto_page_break  : bool
Automatic page breaking.
$_break_margin  : float
Break page margin size, the bottom margin which triggers a page break.
$_buffer  : string
Buffer holding in-memory Pdf.
$_buflen  : int
Buffer length, including already flushed content.
$_cell_margin  : float
Cell margin size.
$_color_flag  : bool
Whether text color is different from fill color.
$_compress  : bool
Flag indicating if PDF file is to be compressed or not.
$_core_fonts  : array<string|int, mixed>
An array of standard font names.
$_current_font  : array<string|int, mixed>
An array containing current font info.
$_current_orientation  : string
The current page orientation.
$_default_orientation  : string
The default page orientation.
$_diffs  : array<string|int, mixed>
An array of encoding differences.
$_draw_color  : string
Commands for drawing color.
$_fill_color  : string
Commands for filling color.
$_flushed  : bool
Whether the buffer has been flushed already.
$_font_family  : string
Current font family.
$_font_files  : array<string|int, mixed>
An array of font files.
$_font_size  : float
Current font size in user units.
$_font_size_pt  : float
Current font size in points.
$_font_style  : string
Current font style.
$_font_widths  : array<string|int, mixed>
Widths of specific font files
$_fonts  : array<string|int, mixed>
An array of used fonts.
$_images  : array<string|int, mixed>
An array of used images.
$_in_footer  : bool
Flag set when processing footer.
$_info  : array<string|int, mixed>
An array containing the document info, consisting of: - title - subject - author - keywords - creator
$_last_height  : float
The height of the last cell printed.
$_layout_mode  : string
Layout display mode.
$_left_margin  : float
Left page margin size.
$_line_width  : float
Line width in user units.
$_links  : array<string|int, mixed>
An array of internal links.
$_n  : int
Current object number.
$_offsets  : array<string|int, mixed>
Array of object offsets.
$_orientation_changes  : array<string|int, mixed>
Array indicating orientation changes.
$_page  : int
Current page number.
$_page_break_trigger  : float
Threshold used to trigger page breaks.
$_page_links  : array<string|int, mixed>
An array of links in pages.
$_pages  : array<string|int, mixed>
Array containing the pages.
$_right_margin  : float
Right page margin size.
$_scale  : float
Scale factor (number of points in user units).
$_state  : int
Current document state.<pre> 0 - initial state 1 - document opened 2 - page opened 3 - document closed </pre>
$_text_color  : string
Commands for text color.
$_top_margin  : float
Top page margin size.
$_underline  : bool
Underlining flag.
$_word_spacing  : int
Word spacing.
$_zoom_mode  : string
Zoom display mode.
__construct()  : mixed
Constructor
acceptPageBreak()  : bool
Whenever a page break condition is met, the method is called, and the break is issued or not depending on the returned value. The default implementation returns a value according to the mode selected by {@link setAutoPageBreak()}.
addFont()  : mixed
Imports a TrueType or Type1 font and makes it available. It is necessary to generate a font definition file first with the makefont.php utility.
addLink()  : mixed
Creates a new internal link and returns its identifier.
addPage()  : mixed
Adds a new page to the document.
aliasNbPages()  : mixed
Defines an alias for the total number of pages.
cell()  : mixed
Prints a cell (rectangular area) with optional borders, background color and character string.
circle()  : mixed
Outputs a circle. It can be drawn (border only), filled (with no border) or both.
close()  : mixed
Terminates the PDF document.
flush()  : mixed
Returns the current buffer content and resets the buffer.
footer()  : mixed
This method is used to render the page footer.
getDefaultOrientation()  : string
P (portrait) or L (landscape)
getDrawColor()  : string
Get the draw color
getFillColor()  : string
Get the fill color
getFormatHeight()  : float
getFormatWidth()  : float
getOutput()  : mixed
Returns the raw Pdf file.
getPage()  : int
Get the current page
getPageHeight()  : float
Returns the actual page height.
getPageNo()  : int
Returns the current page number.
getPageWidth()  : float
Returns the actual page width.
getScale()  : int
getStringWidth()  : float
Returns the length of a text string. A font must be selected.
getTextColor()  : string
Get the text color
getX()  : float
Returns the abscissa of the current position in user units.
getY()  : float
Returns the ordinate of the current position in user units.
header()  : mixed
This method is used to render the page header.
image()  : mixed
Prints an image in the page.
line()  : mixed
Draws a line between two points.
link()  : mixed
Puts a link on a rectangular area of the page.
multiCell()  : mixed
This method allows printing text with line breaks.
newLine()  : mixed
Performs a line break.
open()  : mixed
This method begins the generation of the PDF document; it must be called before any output commands.
rect()  : mixed
Outputs a rectangle.
save()  : mixed
Saves the PDF file on the filesystem.
setAutoPageBreak()  : mixed
Enables or disables the automatic page breaking mode.
setCompression()  : mixed
Activates or deactivates page compression.
setDisplayMode()  : mixed
Defines the way the document is to be displayed by the viewer.
setDrawColor()  : mixed
Sets the draw color, used when drawing lines.
setFillColor()  : mixed
Sets the fill color.
setFont()  : mixed
Sets the font used to print character strings.
setFontSize()  : mixed
Defines the size of the current font.
setFontStyle()  : mixed
Defines the style of the current font.
setInfo()  : mixed
Set the info to a document.
setLeftMargin()  : mixed
Defines the left margin.
setLineWidth()  : mixed
Defines the line width.
setLink()  : mixed
Defines the page and position a link points to.
setMargins()  : mixed
Defines the left, top and right margins.
setPage()  : mixed
Set the current page
setRightMargin()  : mixed
Defines the right margin.
setTextColor()  : mixed
Sets the text color.
setTopMargin()  : mixed
Defines the top margin.
setX()  : mixed
Defines the abscissa of the current position.
setXY()  : mixed
Defines the abscissa and ordinate of the current position.
setY()  : mixed
Defines the ordinate of the current position.
text()  : mixed
Prints a character string.
write()  : mixed
This method prints text from the current position.
writeRotated()  : mixed
Writes text at an angle.
_beginDoc()  : void
Begin the PDF document.
_beginPage()  : void
Begin a new page.
_doUnderline()  : string
Underline a block of text.
_endDoc()  : void
End the PDF document
_endPage()  : void
Set the end of page contents.
_escape()  : string
Escape parentheses and forward slash.
_freadInt()  : int
Read a 4-byte integer from stream.
_getFontFile()  : array<string|int, mixed>
Load information about a font from its key name.
_hexToRgb()  : mixed
Convert hex-based color to RGB
_link()  : void
Save link to page links array.
_newobj()  : void
Begin a new object.
_out()  : void
Add a line to the document.
_parseJPG()  : array<string|int, mixed>
Extract info from a JPEG file.
_parsePNG()  : array<string|int, mixed>
Extract info from a PNG file.
_putCatalog()  : void
Write the PDF catalog.
_putFonts()  : void
Write the PDF fonts.
_putImages()  : void
Write the PDF images.
_putInfo()  : void
Write the PDF information.
_putPages()  : void
Write the PDF pages.
_putResources()  : void
Write the PDF resources.
_putStream()  : void
Add a line to the document wrapped in 'stream' and 'endstream'.
_putTrailer()  : void
Write the PDF trailer.
_textString()  : string
Format a text string by escaping and wrapping in parentheses.
_toPt()  : int
Scale a value.

Properties

$fh

Current height of page format in user units.

public float $fh

$fhPt

Current height of page format in points.

public float $fhPt

$fw

Current width of page format in user units.

public float $fw

$fwPt

Current width of page format in points.

public float $fwPt

$h

Current height of page in user units

public float $h

$hPt

Current height of page in points.

public float $hPt

$w

Current width of page in user units

public float $w

$wPt

Current width of page in points.

public float $wPt

$x

The current horizontal position for cell positioning.

public float $x

Value is set in user units and is calculated from the top left corner as origin.

$y

The current vertical position for cell positioning.

public float $y

Value is set in user units and is calculated from the top left corner as origin.

$_alias_nb_pages

Alias for total number of pages.

protected string $_alias_nb_pages = '{nb}'

$_auto_page_break

Automatic page breaking.

protected bool $_auto_page_break

$_break_margin

Break page margin size, the bottom margin which triggers a page break.

protected float $_break_margin

$_buffer

Buffer holding in-memory Pdf.

protected string $_buffer = ''

$_buflen

Buffer length, including already flushed content.

protected int $_buflen = 0

$_cell_margin

Cell margin size.

protected float $_cell_margin

$_color_flag

Whether text color is different from fill color.

protected bool $_color_flag = alse

$_compress

Flag indicating if PDF file is to be compressed or not.

protected bool $_compress

$_core_fonts

An array of standard font names.

protected array<string|int, mixed> $_core_fonts = array('courier' => 'Courier', 'courierB' => 'Courier-Bold', 'courierI' => 'Courier-Oblique', 'courierBI' => 'Courier-BoldOblique', 'helvetica' => 'Helvetica', 'helveticaB' => 'Helvetica-Bold', 'helveticaI' => 'Helvetica-Oblique', 'helveticaBI' => 'Helvetica-BoldOblique', 'times' => 'Times-Roman', 'timesB' => 'Times-Bold', 'timesI' => 'Times-Italic', 'timesBI' => 'Times-BoldItalic', 'symbol' => 'Symbol', 'zapfdingbats' => 'ZapfDingbats')

$_current_font

An array containing current font info.

protected array<string|int, mixed> $_current_font

$_current_orientation

The current page orientation.

protected string $_current_orientation

$_default_orientation

The default page orientation.

protected string $_default_orientation

$_diffs

An array of encoding differences.

protected array<string|int, mixed> $_diffs = array()

$_draw_color

Commands for drawing color.

protected string $_draw_color = '0 G'

$_fill_color

Commands for filling color.

protected string $_fill_color = '0 g'

$_flushed

Whether the buffer has been flushed already.

protected bool $_flushed = alse

$_font_family

Current font family.

protected string $_font_family = ''

$_font_files

An array of font files.

protected array<string|int, mixed> $_font_files = array()

$_font_size

Current font size in user units.

protected float $_font_size = 12

$_font_size_pt

Current font size in points.

protected float $_font_size_pt = 12

$_font_style

Current font style.

protected string $_font_style = ''

$_font_widths

Widths of specific font files

protected static array<string|int, mixed> $_font_widths = array()

$_fonts

An array of used fonts.

protected array<string|int, mixed> $_fonts = array()

$_images

An array of used images.

protected array<string|int, mixed> $_images = array()

Flag set when processing footer.

protected bool $_in_footer = alse

$_info

An array containing the document info, consisting of: - title - subject - author - keywords - creator

protected array<string|int, mixed> $_info = array()

$_last_height

The height of the last cell printed.

protected float $_last_height

$_layout_mode

Layout display mode.

protected string $_layout_mode

$_left_margin

Left page margin size.

protected float $_left_margin

$_line_width

Line width in user units.

protected float $_line_width

An array of internal links.

protected array<string|int, mixed> $_links = array()

$_n

Current object number.

protected int $_n = 2

$_offsets

Array of object offsets.

protected array<string|int, mixed> $_offsets = array()

$_orientation_changes

Array indicating orientation changes.

protected array<string|int, mixed> $_orientation_changes = array()

$_page

Current page number.

protected int $_page = 0

$_page_break_trigger

Threshold used to trigger page breaks.

protected float $_page_break_trigger

An array of links in pages.

protected array<string|int, mixed> $_page_links

$_pages

Array containing the pages.

protected array<string|int, mixed> $_pages = array()

$_right_margin

Right page margin size.

protected float $_right_margin

$_scale

Scale factor (number of points in user units).

protected float $_scale

$_state

Current document state.<pre> 0 - initial state 1 - document opened 2 - page opened 3 - document closed </pre>

protected int $_state = 0

$_text_color

Commands for text color.

protected string $_text_color = '0 g'

$_top_margin

Top page margin size.

protected float $_top_margin

$_underline

Underlining flag.

protected bool $_underline = alse

$_word_spacing

Word spacing.

protected int $_word_spacing = 0

$_zoom_mode

Zoom display mode.

protected string $_zoom_mode

Methods

__construct()

Constructor

public __construct([array<string|int, mixed> $params = array() ]) : mixed

It allows to set up the page format, the orientation and the units of measurement used in all the methods (except for the font sizes).

Example: $pdf = new Horde_Pdf_Writer(array('orientation' => 'P', 'unit' => 'mm', 'format' => 'A4'));

Parameters
$params : array<string|int, mixed> = array()

A hash with parameters for the created PDF object. Possible parameters are:

  • orientation - Default page orientation. Possible values are (case insensitive):
    • P or Portrait (default)
    • L or Landscape
  • unit - User measure units. Possible values values are:
    • pt: point
    • mm: millimeter (default)
    • cm: centimeter
    • in: inch A point equals 1/72 of inch, that is to say about 0.35 mm (an inch being 2.54 cm). This is a very common unit in typography; font sizes are expressed in that unit.
  • format - The format used for pages. It can be either one of the following values (case insensitive):
    • A3
    • A4 (default)
    • A5
    • Letter
    • Legal or a custom format in the form of a two-element array containing the width and the height (expressed in the unit given by the unit parameter).
Return values
mixed

acceptPageBreak()

Whenever a page break condition is met, the method is called, and the break is issued or not depending on the returned value. The default implementation returns a value according to the mode selected by {@link setAutoPageBreak()}.

public acceptPageBreak() : bool

This method is called automatically and should not be called directly by the application.

Tags
see
setAutoPageBreak()
Return values
bool

addFont()

Imports a TrueType or Type1 font and makes it available. It is necessary to generate a font definition file first with the makefont.php utility.

public addFont(string $family[, string $style = '' ][, string $file = '' ]) : mixed

The location of the definition file (and the font file itself when embedding) must be found at the full path name included.

Example: $pdf->addFont('Comic', 'I'); is equivalent to: $pdf->addFont('Comic', 'I', 'comici.php');

Parameters
$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 (default)
  • B: bold
  • I: italic
  • BI or IB: bold italic
$file : string = ''

The font definition file. By default, the name is built from the family and style, in lower case with no space.

Tags
see
setFont()
todo

Fonts use a class instead of a definition file

Return values
mixed

Creates a new internal link and returns its identifier.

public addLink() : mixed

An internal link is a clickable area which directs to another place within the document.

The identifier can then be passed to , write, or . The destination is defined with .

Tags
see
cell()
see
write()
see
image()
see
link()
see
setLink()
Return values
mixed

addPage()

Adds a new page to the document.

public addPage([string $orientation = '' ]) : mixed

If a page is already present, the 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 is called to display the header.

The font which was set before calling is automatically restored. There is no need to call again if you want to continue with the same font. The same is true for colors and line width. The origin of the coordinate system is at the top-left corner and increasing ordinates go downwards.

Parameters
$orientation : string = ''

Page orientation. Possible values are (case insensitive):

  • P or Portrait
  • L or Landscape The default value is the one passed to the constructor.
Tags
see
header()
see
footer()
see
setMargins()
Return values
mixed

aliasNbPages()

Defines an alias for the total number of pages.

public aliasNbPages([string $alias = '{nb}' ]) : mixed

It will be substituted as the document is closed.

Example: class My_Pdf extends Horde_Pdf_Writer { function footer() { // Go to 1.5 cm from bottom $this->setY(-15); // Select Arial italic 8 $this->setFont('Arial', 'I', 8); // Print current and total page numbers $this->cell(0, 10, 'Page ' . $this->getPageNo() . '/{nb}', 0, 0, 'C'); } } $pdf = new My_Pdf(); $pdf->aliasNbPages();

Parameters
$alias : string = '{nb}'

The alias.

Tags
see
getPageNo()
see
footer()
Return values
mixed

cell()

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

public cell(float $width, float $height[, string $text = '' ], mixed $border, int $ln[, string $align = '' ], int $fill[, string $link = '' ]) : mixed

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
$width : float

Cell width. If 0, the cell extends up to the right margin.

$height : float

Cell height.

$text : string = ''

String to print.

$border : mixed

Indicates if borders must be drawn around the cell. The value can be either a number:

  • 0: no border (default)
  • 1: frame or a string containing some or all of the following characters (in any order):
  • L: left
  • T: top
  • R: right
  • B: bottom
$ln : int

Indicates where the current position should go after the call. Possible values are:

  • 0: to the right (default)
  • 1: to the beginning of the next line
  • 2: below Putting 1 is equivalent to putting 0 and calling just after.
$align : string = ''

Allows to center or align the text. Possible values are:

  • L or empty string: left (default)
  • C: center
  • R: right
$fill : int

Indicates if the cell fill type. Possible values are:

  • 0: transparent (default)
  • 1: painted
$link : string = ''

URL or identifier returned by .

Tags
see
setFont()
see
setDrawColor()
see
setFillColor()
see
setLineWidth()
see
addLink()
see
newLine()
see
multiCell()
see
write()
see
setAutoPageBreak()
Return values
mixed

circle()

Outputs a circle. It can be drawn (border only), filled (with no border) or both.

public circle(float $x, float $y, float $r[, string $style = '' ]) : mixed

All coordinates can be negative to provide values from the right or bottom edge of the page (since File_Pdf 0.2.0, Horde 3.2).

Parameters
$x : float

Abscissa of the center of the circle.

$y : float

Ordinate of the center of the circle.

$r : float

Circle radius.

$style : string = ''

Style of rendering. Possible values are:

  • D or empty string: draw (default)
  • F: fill
  • DF or FD: draw and fill
Return values
mixed

close()

Terminates the PDF document.

public close() : mixed

If the document contains no page, is called to prevent from getting an invalid document.

Tags
see
open()
Return values
mixed

flush()

Returns the current buffer content and resets the buffer.

public flush() : mixed

Use this method when creating large files to avoid memory problems. This method doesn't work in combination with the save() method, use getOutput() at the end. Calling this method doubles the memory usage during the call.

Tags
see
getOutput()
Return values
mixed

This method is used to render the page footer.

public footer() : mixed

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

Example: class My_Pdf extends Horde_Pdf_Writer { function footer() { // Go to 1.5 cm from bottom $this->setY(-15); // Select Arial italic 8 $this->setFont('Arial', 'I', 8); // Print centered page number $this->cell(0, 10, 'Page ' . $this->getPageNo(), 0, 0, 'C'); } }

Tags
see
header()
Return values
mixed

getDefaultOrientation()

P (portrait) or L (landscape)

public getDefaultOrientation() : string
Return values
string

getDrawColor()

Get the draw color

public getDrawColor() : string
Return values
string

getFillColor()

Get the fill color

public getFillColor() : string
Return values
string

getFormatHeight()

public getFormatHeight() : float
Return values
float

getFormatWidth()

public getFormatWidth() : float
Return values
float

getOutput()

Returns the raw Pdf file.

public getOutput() : mixed
Tags
see
flush()
Return values
mixed

getPage()

Get the current page

public getPage() : int
Return values
int

getPageHeight()

Returns the actual page height.

public getPageHeight() : float
Return values
float

The page height.

getPageNo()

Returns the current page number.

public getPageNo() : int
Tags
see
aliasNbPages()
Return values
int

getPageWidth()

Returns the actual page width.

public getPageWidth() : float
Return values
float

The page width.

getScale()

public getScale() : int
Return values
int

getStringWidth()

Returns the length of a text string. A font must be selected.

public getStringWidth(string $text[, bool $pt = false ]) : float
Parameters
$text : string

The text whose length is to be computed.

$pt : bool = false

Whether the width should be returned in points or user units.

Return values
float

getTextColor()

Get the text color

public getTextColor() : string
Return values
string

getX()

Returns the abscissa of the current position in user units.

public getX() : float
Tags
see
setX()
see
getY()
see
setY()
Return values
float

getY()

Returns the ordinate of the current position in user units.

public getY() : float
Tags
see
setY()
see
getX()
see
setX()
Return values
float

header()

This method is used to render the page header.

public header() : mixed

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

Example: class My_Pdf extends Horde_Pdf_Writer { function header() { // Select Arial bold 15 $this->setFont('Arial', 'B', 15); // Move to the right $this->cell(80); // Framed title $this->cell(30, 10, 'Title', 1, 0, 'C'); // Line break $this->newLine(20); } }

Tags
see
footer()
Return values
mixed

image()

Prints an image in the page.

public image(string $file, float $x, float $y, float $width, float $height[, string $type = '' ][, mixed $link = '' ]) : mixed

The upper-left corner and at least one of the dimensions must be specified; the height or the width can be calculated automatically in order to keep the image proportions. Supported formats are JPEG and PNG.

All coordinates can be negative to provide values from the right or bottom edge of the page (since File_Pdf 0.2.0, Horde 3.2).

For JPEG, all flavors are allowed:

  • gray scales
  • true colors (24 bits)
  • CMYK (32 bits)

For PNG, are allowed:

  • gray scales on at most 8 bits (256 levels)
  • indexed colors
  • true colors (24 bits) but are not supported:
  • Interlacing
  • Alpha channel

If a transparent color is defined, it will be taken into account (but will be only interpreted by Acrobat 4 and above). 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 will be embedded in the file.

Parameters
$file : string

Name of the file containing the image.

$x : float

Abscissa of the upper-left corner.

$y : float

Ordinate of the upper-left corner.

$width : float

Width of the image in the page. If equal to zero, it is automatically calculated to keep the original proportions.

$height : float

Height of the image in the page. If not specified or equal to zero, it is automatically calculated to keep the original proportions.

$type : string = ''

Image format. Possible values are (case insensitive): JPG, JPEG, PNG. If not specified, the type is inferred from the file extension.

$link : mixed = ''

URL or identifier returned by .

Tags
see
addLink()
Return values
mixed

line()

Draws a line between two points.

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

All coordinates can be negative to provide values from the right or bottom edge of the page (since File_Pdf 0.2.0, Horde 3.2).

Parameters
$x1 : float

Abscissa of first point.

$y1 : float

Ordinate of first point.

$x2 : float

Abscissa of second point.

$y2 : float

Ordinate of second point.

Tags
see
setLineWidth()
see
setDrawColor()
Return values
mixed

Puts a link on a rectangular area of the page.

public link(float $x, float $y, float $width, float $height, mixed $link) : mixed

Text or image links are generally put via , or , but this method can be useful for instance to define a clickable area inside an image.

All coordinates can be negative to provide values from the right or bottom edge of the page (since File_Pdf 0.2.0, Horde 3.2).

Parameters
$x : float

Abscissa of the upper-left corner of the rectangle.

$y : float

Ordinate of the upper-left corner of the rectangle.

$width : float

Width of the rectangle.

$height : float

Height of the rectangle.

$link : mixed

URL or identifier returned by .

Tags
see
addLink()
see
cell()
see
write()
see
image()
Return values
mixed

multiCell()

This method allows printing text with line breaks.

public multiCell(float $width, float $height, string $text, mixed $border[, string $align = 'J' ], int $fill) : mixed

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
$width : float

Width of cells. If 0, they extend up to the right margin of the page.

$height : float

Height of cells.

$text : string

String to print.

$border : mixed

Indicates if borders must be drawn around the cell block. The value can be either a number:

  • 0: no border (default)
  • 1: frame or a string containing some or all of the following characters (in any order):
  • L: left
  • T: top
  • R: right
  • B: bottom
$align : string = 'J'

Sets the text alignment. Possible values are:

  • L: left alignment
  • C: center
  • R: right alignment
  • J: justification (default value)
$fill : int

Indicates if the cell background must:

  • 0: transparent (default)
  • 1: painted
Tags
see
setFont()
see
setDrawColor()
see
setFillColor()
see
setLineWidth()
see
cell()
see
write()
see
setAutoPageBreak()
Return values
mixed

newLine()

Performs a line break.

public newLine([float $height = '' ]) : mixed

The current abscissa goes back to the left margin and the ordinate increases by the amount passed in parameter.

Parameters
$height : float = ''

The height of the break. By default, the value equals the height of the last printed cell.

Tags
see
cell()
Return values
mixed

open()

This method begins the generation of the PDF document; it must be called before any output commands.

public open() : mixed

No page is created by this method, therefore it is necessary to call .

Tags
see
addPage()
see
close()
Return values
mixed

rect()

Outputs a rectangle.

public rect(float $x, float $y, float $width, float $height[, float $style = '' ]) : mixed

It can be drawn (border only), filled (with no border) or both.

All coordinates can be negative to provide values from the right or bottom edge of the page (since File_Pdf 0.2.0, Horde 3.2).

Parameters
$x : float

Abscissa of upper-left corner.

$y : float

Ordinate of upper-left corner.

$width : float

Width.

$height : float

Height.

$style : float = ''

Style of rendering. Possible values are:

  • D or empty string: draw (default)
  • F: fill
  • DF or FD: draw and fill
Tags
see
setLineWidth()
see
setDrawColor()
see
setFillColor()
Return values
mixed

save()

Saves the PDF file on the filesystem.

public save([string $filename = 'unknown.pdf' ]) : mixed
Parameters
$filename : string = 'unknown.pdf'

The filename for the output file.

Return values
mixed

setAutoPageBreak()

Enables or disables the automatic page breaking mode.

public setAutoPageBreak(bool $auto, float $margin) : mixed

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
$auto : bool

Boolean indicating if mode should be on or off.

$margin : float

Distance from the bottom of the page.

Return values
mixed

setCompression()

Activates or deactivates page compression.

public setCompression(bool $compress) : mixed

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
$compress : bool

Boolean indicating if compression must be enabled or not.

Return values
mixed

setDisplayMode()

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

public setDisplayMode(mixed $zoom[, mixed $layout = 'continuous' ]) : mixed

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 Acrobat). The page layout can be specified too: single at once, continuous display, two columns or viewer default. By default, documents use the full width mode with continuous display.

Parameters
$zoom : mixed

The zoom to use. It can be one of the following string values:

  • fullpage: entire page on screen
  • fullwidth: maximum width of window
  • real: uses real size (100% zoom)
  • default: uses viewer default mode or a number indicating the zooming factor.
$layout : mixed = 'continuous'
Return values
mixed

setDrawColor()

Sets the draw color, used when drawing lines.

public setDrawColor([string $cs = 'rgb' ], float $c1, float $c2, float $c3, float $c4) : mixed

Depending on the colorspace called, the number of color component parameters required can be either 1, 3 or 4. The method can be called before the first page is created and the color is retained from page to page.

Parameters
$cs : string = 'rgb'

Indicates the colorspace which can be either 'rgb', 'hex', 'cmyk' or 'gray'. Defaults to 'rgb'.

$c1 : float

First color component, floating point value between 0 and 1. Required for gray, rgb and cmyk.

$c2 : float

Second color component, floating point value between 0 and 1. Required for rgb and cmyk.

$c3 : float

Third color component, floating point value between 0 and 1. Required for rgb and cmyk.

$c4 : float

Fourth color component, floating point value between 0 and 1. Required for cmyk.

Tags
see
setFillColor()
see
line()
see
rect()
see
cell()
see
multiCell()
Return values
mixed

setFillColor()

Sets the fill color.

public setFillColor([string $cs = 'rgb' ], float $c1, float $c2, float $c3, float $c4) : mixed

Depending on the colorspace called, the number of color component parameters required can be either 1, 3 or 4. The method can be called before the first page is created and the color is retained from page to page.

Parameters
$cs : string = 'rgb'

Indicates the colorspace which can be either 'rgb', 'hex', 'cmyk', or 'gray'. Defaults to 'rgb'.

$c1 : float

First color component, floating point value between 0 and 1. Required for gray, rgb and cmyk.

$c2 : float

Second color component, floating point value between 0 and 1. Required for rgb and cmyk.

$c3 : float

Third color component, floating point value between 0 and 1. Required for rgb and cmyk.

$c4 : float

Fourth color component, floating point value between 0 and 1. Required for cmyk.

Tags
see
setTextColor()
see
setDrawColor()
see
rect()
see
cell()
see
multiCell()
Return values
mixed

setFont()

Sets the font used to print character strings.

public setFont(string $family[, string $style = '' ][, int $size = null ][, bool $force = false ]) : mixed

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 method. Standard fonts use Windows encoding cp1252 (Western Europe).

The method can be called before the first page is created and the font is retained from page to page.

If you just wish to change the current font size, it is simpler to call .

Parameters
$family : string

Family font. It can be either a name defined by or one of the standard families (case insensitive):

  • Courier (fixed-width)
  • Helvetica or Arial (sans serif)
  • Times (serif)
  • Symbol (symbolic)
  • ZapfDingbats (symbolic) It is also possible to pass an empty string. In that case, the current family is retained.
$style : string = ''

Font style. Possible values are (case insensitive):

  • empty string: regular
  • B: bold
  • I: italic
  • U: underline or any combination. Bold and italic styles do not apply to Symbol and ZapfDingbats.
$size : int = null

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.

$force : bool = false

Force the setting of the font. Each new page will require a new call to and setting this to true will make sure that the checks for same font calls will be skipped.

Tags
see
addFont()
see
setFontSize()
see
cell()
see
multiCell()
see
write()
Return values
mixed

setFontSize()

Defines the size of the current font.

public setFontSize(float $size) : mixed
Parameters
$size : float

The size (in points).

Tags
see
setFont()
Return values
mixed

setFontStyle()

Defines the style of the current font.

public setFontStyle(string $style) : mixed
Parameters
$style : string

The font style.

Tags
see
setFont()
Return values
mixed

setInfo()

Set the info to a document.

public setInfo(array<string|int, mixed>|string $info[, string $value = '' ]) : mixed

Possible info settings are:

  • title
  • subject
  • author
  • keywords
  • creator
Parameters
$info : array<string|int, mixed>|string

If passed as an array then the complete hash containing the info to be inserted into the document. Otherwise the name of setting to be set.

$value : string = ''

The value of the setting.

Return values
mixed

setLeftMargin()

Defines the left margin.

public setLeftMargin(float $margin) : mixed

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

Parameters
$margin : float

The margin.

Tags
see
setAutoPageBreak()
see
setMargins()
see
setRightMargin()
see
setTopMargin()
Return values
mixed

setLineWidth()

Defines the line width.

public setLineWidth(float $width) : mixed

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
$width : float

The width.

Tags
see
line()
see
rect()
see
cell()
see
multiCell()
Return values
mixed

Defines the page and position a link points to.

public setLink(int $link, float $y[, int $page = -1 ]) : mixed
Parameters
$link : int

The link identifier returned by .

$y : float

Ordinate of target position; -1 indicates the current position. The default value is 0 (top of page).

$page : int = -1

Number of target page; -1 indicates the current page.

Tags
see
addLink()
Return values
mixed

setMargins()

Defines the left, top and right margins.

public setMargins(float $left, float $top[, float $right = null ]) : mixed

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

Parameters
$left : float

Left margin.

$top : float

Top margin.

$right : float = null

Right margin. If not specified default to the value of the left one.

Tags
see
setAutoPageBreak()
see
setLeftMargin()
see
setRightMargin()
see
setTopMargin()
Return values
mixed

setPage()

Set the current page

public setPage(int $page) : mixed
Parameters
$page : int
Return values
mixed

setRightMargin()

Defines the right margin.

public setRightMargin(float $margin) : mixed

The method can be called before creating the first page.

Parameters
$margin : float

The margin.

Return values
mixed

setTextColor()

Sets the text color.

public setTextColor([string $cs = 'rgb' ], float $c1, float $c2, float $c3, float $c4) : mixed

Depending on the colorspace called, the number of color component parameters required can be either 1, 3 or 4. The method can be called before the first page is created and the color is retained from page to page.

Parameters
$cs : string = 'rgb'

Indicates the colorspace which can be either 'rgb', 'hex', 'cmyk' or 'gray'. Defaults to 'rgb'.

$c1 : float

First color component, floating point value between 0 and 1. Required for gray, rgb and cmyk.

$c2 : float

Second color component, floating point value between 0 and 1. Required for rgb and cmyk.

$c3 : float

Third color component, floating point value between 0 and 1. Required for rgb and cmyk.

$c4 : float

Fourth color component, floating point value between 0 and 1. Required for cmyk.

Tags
see
setFillColor()
see
setDrawColor()
see
rect()
see
cell()
see
multiCell()
Return values
mixed

setTopMargin()

Defines the top margin.

public setTopMargin(float $margin) : mixed

The method can be called before creating the first page.

Parameters
$margin : float

The margin.

Return values
mixed

setX()

Defines the abscissa of the current position.

public setX(float $x) : mixed

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

Parameters
$x : float

The value of the abscissa.

Tags
see
getX()
see
getY()
see
setY()
see
setXY()
Return values
mixed

setXY()

Defines the abscissa and ordinate of the current position.

public setXY(float $x, float $y) : mixed

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

Parameters
$x : float

The value of the abscissa.

$y : float

The value of the ordinate.

Tags
see
setX()
see
setY()
Return values
mixed

setY()

Defines the ordinate of the current position.

public setY(float $y) : mixed

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

Parameters
$y : float

The value of the ordinate.

Tags
see
getX()
see
getY()
see
setY()
see
setXY()
Return values
mixed

text()

Prints a character string.

public text(float $x, float $y, string $text) : mixed

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 , or which are the standard methods to print text.

All coordinates can be negative to provide values from the right or bottom edge of the page (since File_Pdf 0.2.0, Horde 3.2).

Parameters
$x : float

Abscissa of the origin.

$y : float

Ordinate of the origin.

$text : string

String to print.

Tags
see
setFont()
see
cell()
see
multiCell()
see
write()
Return values
mixed

write()

This method prints text from the current position.

public write(float $height, string $text[, mixed $link = '' ]) : mixed

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.

Example: // Begin with regular font $pdf->setFont('Arial', '', 14); $pdf->write(5, 'Visit '); // Then put a blue underlined link $pdf->setTextColor(0, 0, 255); $pdf->setFont('', 'U'); $pdf->write(5, 'www.fpdf.org', 'http://www.fpdf.org');

Parameters
$height : float

Line height.

$text : string

String to print.

$link : mixed = ''

URL or identifier returned by .

Tags
see
setFont()
see
addLink()
see
multiCell()
see
setAutoPageBreak()
Return values
mixed

writeRotated()

Writes text at an angle.

public writeRotated(int $x, int $y, string $text, float $text_angle, float $font_angle) : mixed

All coordinates can be negative to provide values from the right or bottom edge of the page (since File_Pdf 0.2.0, Horde 3.2).

Parameters
$x : int

X coordinate.

$y : int

Y coordinate.

$text : string

Text to write.

$text_angle : float

Angle to rotate (Eg. 90 = bottom to top).

$font_angle : float

Rotate characters as well as text.

Tags
see
setFont()
Return values
mixed

_beginDoc()

Begin the PDF document.

protected _beginDoc() : void
Return values
void

_beginPage()

Begin a new page.

protected _beginPage(string $orientation) : void
Parameters
$orientation : string

Orientation code

Return values
void

_doUnderline()

Underline a block of text.

protected _doUnderline(int $x, int $y, string $text) : string
Parameters
$x : int

X-coordinate

$y : int

Y-coordinate

$text : string

Text to underline

Return values
string

Underlined string

_endDoc()

End the PDF document

protected _endDoc() : void
Return values
void

_endPage()

Set the end of page contents.

protected _endPage() : void
Return values
void

_escape()

Escape parentheses and forward slash.

protected _escape(string $s) : string
Parameters
$s : string

String to escape.

Return values
string

Escaped string.

_freadInt()

Read a 4-byte integer from stream.

protected _freadInt(resource $f) : int
Parameters
$f : resource

Stream resource

Return values
int

Byte

_getFontFile()

Load information about a font from its key name.

protected static _getFontFile(string $fontkey) : array<string|int, mixed>
Parameters
$fontkey : string

Font name key

Return values
array<string|int, mixed>

Array of all font widths, including this font.

_hexToRgb()

Convert hex-based color to RGB

protected _hexToRgb(mixed $hex) : mixed
Parameters
$hex : mixed
Return values
mixed

Save link to page links array.

protected _link(int $x, int $y, int $width, int $height, string $link) : void
Parameters
$x : int

X-coordinate

$y : int

Y-coordinate

$width : int

Width

$height : int

Height

$link : string

Link

Return values
void

_newobj()

Begin a new object.

protected _newobj() : void
Return values
void

_out()

Add a line to the document.

protected _out(string $s) : void
Parameters
$s : string

Line to add.

Return values
void

_parseJPG()

Extract info from a JPEG file.

protected _parseJPG(string $file) : array<string|int, mixed>
Parameters
$file : string

Filename of JPEG image

Return values
array<string|int, mixed>

Assoc. array of info

_parsePNG()

Extract info from a PNG file.

protected _parsePNG(string $file) : array<string|int, mixed>
Parameters
$file : string

Filename of PNG image

Return values
array<string|int, mixed>

Assoc. array of info

_putCatalog()

Write the PDF catalog.

protected _putCatalog() : void
Return values
void

_putFonts()

Write the PDF fonts.

protected _putFonts() : void
Return values
void

_putImages()

Write the PDF images.

protected _putImages() : void
Return values
void

_putInfo()

Write the PDF information.

protected _putInfo() : void
Return values
void

_putPages()

Write the PDF pages.

protected _putPages() : void
Return values
void

_putResources()

Write the PDF resources.

protected _putResources() : void
Return values
void

_putStream()

Add a line to the document wrapped in 'stream' and 'endstream'.

protected _putStream(string $s) : void
Parameters
$s : string

Line to add.

Return values
void

_putTrailer()

Write the PDF trailer.

protected _putTrailer() : void
Return values
void

_textString()

Format a text string by escaping and wrapping in parentheses.

protected _textString(string $s) : string
Parameters
$s : string

String to format.

Return values
string

_toPt()

Scale a value.

protected _toPt(int $val) : int
Parameters
$val : int

Value

Return values
int

Value multiplied by scale

Search results