Reporting in PHP (Day-2)
Reporting in PHP (Day-2)
<?php
require("../fpdf/fpdf.php"); // path to fpdf.php
?>
Documents and Pages (contd…)
Example# 1:
<?php
require("../fpdf/fpdf.php"); // path to fpdf.php
$pdf = new FPDF( ); // create object of FPDF
$pdf->AddPage( ); // add a page to document
$pdf->SetFont('Arial','B',16); // set fonts of the text
$pdf->Cell(40,10,'Hello Out There!'); // add text to the page
$pdf->Output( ); // send document to browser,
means output the document
?>
FPDF ( ) constructor parameters Parameter options
P
Portrait; default
Orientation
L
Landscape
pt
Point (1/72 of an inch)
in
Inch
Units of Measurement
mm (default)
Millimeter
cm
Centimeter
Letter Legal
A5
Page Size A3
A4- (default)
An array containing width and height
AddPage()
Syntax:
AddPage([string orientation [, mixed size [, int rotation]]])
Description:
Adds a new page to the document.
Parameters:
orientation: Page orientation. Possible values are (case insensitive):
P or Portrait, L or Landscape
The default value is the one passed to the constructor.
size: Page size. 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 user unit).
Default values are that of a constructor..
Rotation: Angle by which to rotate the page. It must be a multiple of 90; positive
values mean clockwise rotation. The default value is 0.
SetFont()
Syntax:
SetFont(string family [, string style [, float size]])
Description:
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.
Cell()
Syntax:
Cell(float w [, float h [, string txt [, mixed border [, int ln [, string align [, int
fill [, mixed link]]]]]]])
Description:
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.
SetFillColor()
Syntax:
SetFillColor(int r [, int g, int b])
Description:
Defines the color used for all filling operations (filled rectangles and
cell backgrounds). 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:
r
If g and b are given, red component; if not, indicates the gray level. Value between 0 and 255.
SetLineWidth()
SetLineWidth(float width)
Description
Defines the line width. 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.
MultiCell()
Syntax:
MultiCell(float w, float h, string txt [, mixed border [, string align
[, boolean fill]]])
Description:
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.
Output()
string Output([string dest [, string name [, boolean isUTF8]]]
Parameters
name:
The name of the file. If not specified, the document will be sent to the browser
(destination I) with the name doc.pdf.
dest:
Destination where to send the document. It can take one of the following values:
I: send the file inline to the browser. The plug-in is used if available. The name given by
name is used when one selects the "Save as" option on the link generating the PDF.
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. name is ignored.
Text()
Syntax:
Text(float x, float y, string txt)
Description:
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 Write() which are the standard methods to print text.
Write()
Syntax:
Write(float h, string txt [, mixed link])
Description:
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.
SetX() & SetY()
Syntax:
SetX(float x)
SetY(float y)
Description:
Sets Position of all preceding elements
Note: SetX and SetY should not be used together. For this purpose
use SetXY()
SetXY()
Syntax:
SetXY(float x, float y)
Description:
Defines the ordinate of the current position. If the passed values
are negative, they are relative respectively to the right and bottom
of the page.
Line()
Syntax:
Line(float x1, float y1, float x2, float y2)
Description:
Draws a line between two points.
Ln()
Syntax:
Ln([float h])
Description:
Performs a line break.
Parameters:
h
The height of the break.
By default, the value equals the height of the last printed cell.