$fwPt
$fwPt : float
Current width of page format in points.
The Horde_Pdf_Writer class provides a PHP-only implementation of a PDF library. No external libs or PHP extensions are required.
__construct(array $params = array())
Constructor
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'));
array | $params | A hash with parameters for the created PDF object. Possible parameters are:
|
setMargins(float $left, float $top, float $right = null)
Defines the left, top and right margins.
By default, they equal 1 cm. Call this method to change them.
float | $left | Left margin. |
float | $top | Top margin. |
float | $right | Right margin. If not specified default to the value of the left one. |
setAutoPageBreak(boolean $auto, float $margin)
Enables or disables the automatic page breaking mode.
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.
boolean | $auto | Boolean indicating if mode should be on or off. |
float | $margin | Distance from the bottom of the page. |
setDisplayMode(mixed $zoom, $layout = 'continuous')
Defines the way the document is to be displayed by the viewer.
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.
mixed | $zoom | The zoom to use. It can be one of the following string values:
|
$layout |
setCompression(boolean $compress)
Activates or deactivates page compression.
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.
boolean | $compress | Boolean indicating if compression must be enabled or not. |
setInfo(array|string $info, string $value = '')
Set the info to a document.
Possible info settings are:
array|string | $info | 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. |
string | $value | The value of the setting. |
aliasNbPages(string $alias = '{nb}')
Defines an alias for the total number of pages.
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();
string | $alias | The alias. |
addPage(string $orientation = '')
Adds a new page to the document.
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 coordinate system is at the top-left corner and increasing ordinates go downwards.
string | $orientation | Page orientation. Possible values are (case insensitive):
|
header()
This method is used to render the page header.
It is automatically called by \addPage() 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);
}
}
footer()
This method is used to render the page footer.
It is automatically called by \addPage() and \close() 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');
}
}
setFillColor(string $cs = 'rgb', float $c1, float $c2, float $c3, float $c4)
Sets the fill color.
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.
string | $cs | Indicates the colorspace which can be either 'rgb', 'hex', 'cmyk', or 'gray'. Defaults to 'rgb'. |
float | $c1 | First color component, floating point value between 0 and 1. Required for gray, rgb and cmyk. |
float | $c2 | Second color component, floating point value between 0 and 1. Required for rgb and cmyk. |
float | $c3 | Third color component, floating point value between 0 and 1. Required for rgb and cmyk. |
float | $c4 | Fourth color component, floating point value between 0 and 1. Required for cmyk. |
setTextColor(string $cs = 'rgb', float $c1, float $c2, float $c3, float $c4)
Sets the text color.
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.
string | $cs | Indicates the colorspace which can be either 'rgb', 'hex', 'cmyk' or 'gray'. Defaults to 'rgb'. |
float | $c1 | First color component, floating point value between 0 and 1. Required for gray, rgb and cmyk. |
float | $c2 | Second color component, floating point value between 0 and 1. Required for rgb and cmyk. |
float | $c3 | Third color component, floating point value between 0 and 1. Required for rgb and cmyk. |
float | $c4 | Fourth color component, floating point value between 0 and 1. Required for cmyk. |
setDrawColor(string $cs = 'rgb', float $c1, float $c2, float $c3, float $c4)
Sets the draw color, used when drawing lines.
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.
string | $cs | Indicates the colorspace which can be either 'rgb', 'hex', 'cmyk' or 'gray'. Defaults to 'rgb'. |
float | $c1 | First color component, floating point value between 0 and 1. Required for gray, rgb and cmyk. |
float | $c2 | Second color component, floating point value between 0 and 1. Required for rgb and cmyk. |
float | $c3 | Third color component, floating point value between 0 and 1. Required for rgb and cmyk. |
float | $c4 | Fourth color component, floating point value between 0 and 1. Required for cmyk. |
line(float $x1, float $y1, float $x2, float $y2)
Draws a line between two points.
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).
float | $x1 | Abscissa of first point. |
float | $y1 | Ordinate of first point. |
float | $x2 | Abscissa of second point. |
float | $y2 | Ordinate of second point. |
rect(float $x, float $y, float $width, float $height, float $style = '')
Outputs a rectangle.
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).
float | $x | Abscissa of upper-left corner. |
float | $y | Ordinate of upper-left corner. |
float | $width | Width. |
float | $height | Height. |
float | $style | Style of rendering. Possible values are:
|
circle(float $x, float $y, float $r, string $style = '')
Outputs a circle. 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).
float | $x | Abscissa of the center of the circle. |
float | $y | Ordinate of the center of the circle. |
float | $r | Circle radius. |
string | $style | Style of rendering. Possible values are:
|
addFont(string $family, string $style = '', string $file = '')
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.
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');
string | $family | Font family. The name can be chosen arbitrarily. If it is a standard family name, it will override the corresponding font. |
string | $style | Font style. Possible values are (case insensitive):
|
string | $file | The font definition file. By default, the name is built from the family and style, in lower case with no space. |
setFont(string $family, string $style = '', integer $size = null, boolean $force = false)
Sets the font used to print character strings.
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 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 \setFontSize().
string | $family | Family font. It can be either a name defined by {@link addFont()} or one of the standard families (case insensitive):
|
string | $style | Font style. Possible values are (case insensitive):
|
integer | $size | 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. |
boolean | $force | Force the setting of the font. Each new page will require a new call to {@link setFont()} and setting this to true will make sure that the checks for same font calls will be skipped. |
setLink(integer $link, float $y, integer $page = -1)
Defines the page and position a link points to.
integer | $link | The link identifier returned by {@link addLink()}. |
float | $y | Ordinate of target position; -1 indicates the current position. The default value is 0 (top of page). |
integer | $page | Number of target page; -1 indicates the current page. |
link(float $x, float $y, float $width, float $height, mixed $link)
Puts a link on a rectangular area of the page.
Text or image links are generally put via \cell(), {@link write()} or \image(), 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).
float | $x | Abscissa of the upper-left corner of the rectangle. |
float | $y | Ordinate of the upper-left corner of the rectangle. |
float | $width | Width of the rectangle. |
float | $height | Height of the rectangle. |
mixed | $link | URL or identifier returned by {@link addLink()}. |
text(float $x, float $y, string $text)
Prints a character string.
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 {@link write()} 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).
float | $x | Abscissa of the origin. |
float | $y | Ordinate of the origin. |
string | $text | String to print. |
acceptPageBreak() : boolean
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()}.
This method is called automatically and should not be called directly by the application.
cell(float $width, float $height, string $text = '', mixed $border, integer $ln, string $align = '', integer $fill, string $link = '')
Prints a cell (rectangular area) with optional borders, background color and character string.
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.
float | $width | Cell width. If 0, the cell extends up to the right margin. |
float | $height | Cell height. |
string | $text | String to print. |
mixed | $border | Indicates if borders must be drawn around the cell. The value can be either a number:
|
integer | $ln | Indicates where the current position should go after the call. Possible values are:
|
string | $align | Allows to center or align the text. Possible values are:
|
integer | $fill | Indicates if the cell fill type. Possible values are:
|
string | $link | URL or identifier returned by {@link addLink()}. |
multiCell(float $width, float $height, string $text, mixed $border, string $align = 'J', integer $fill)
This method allows printing text with line breaks.
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.
float | $width | Width of cells. If 0, they extend up to the right margin of the page. |
float | $height | Height of cells. |
string | $text | String to print. |
mixed | $border | Indicates if borders must be drawn around the cell block. The value can be either a number:
|
string | $align | Sets the text alignment. Possible values are:
|
integer | $fill | Indicates if the cell background must:
|
write(float $height, string $text, mixed $link = '')
This method prints text from the current position.
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');
float | $height | Line height. |
string | $text | String to print. |
mixed | $link | URL or identifier returned by {@link addLink()}. |
writeRotated(integer $x, integer $y, string $text, float $text_angle, float $font_angle)
Writes text at an angle.
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).
integer | $x | X coordinate. |
integer | $y | Y coordinate. |
string | $text | Text to write. |
float | $text_angle | Angle to rotate (Eg. 90 = bottom to top). |
float | $font_angle | Rotate characters as well as text. |
image(string $file, float $x, float $y, float $width, float $height, string $type = '', mixed $link = '')
Prints an image in the page.
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:
For PNG, are allowed:
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.
string | $file | Name of the file containing the image. |
float | $x | Abscissa of the upper-left corner. |
float | $y | Ordinate of the upper-left corner. |
float | $width | Width of the image in the page. If equal to zero, it is automatically calculated to keep the original proportions. |
float | $height | Height of the image in the page. If not specified or equal to zero, it is automatically calculated to keep the original proportions. |
string | $type | Image format. Possible values are (case insensitive): JPG, JPEG, PNG. If not specified, the type is inferred from the file extension. |
mixed | $link | URL or identifier returned by {@link addLink()}. |