PhpFPDF class library application implementation code
The code is as follows:
Require ('Chinese. php ');
Class PDF extends pai_chinese
{
Function Header () // Set the Header
{
$ This-> SetFont ('GB', '', 10 );
$ This-> Write (10, 'XX company product directory ');
$ This-> Ln (20); // line feed
}
Function Footer () // sets the Footer.
{
$ This-> SetY (-15 );
$ This-> SetFont ('GB', '', 10 );
$ This-> Cell (, 'quarter '. $ this-> PageNo (). 'page ');
}
}
$ Conn = mysql_connect ("localhost", "root", ""); // connect to the database
Mysql_select_db ("product", $ conn); // execute SQL
$ Query_rs_prod = "SELECT * FROM product order by prod_id ";
$ Rs_prod = mysql_query ($ query_rs_prod, $ conn) or die (mysql_error ());
$ Row_rs_prod = mysql_fetch_assoc ($ rs_prod );
$ TotalRows_rs_prod = mysql_num_rows ($ rs_prod );
$ Pdf = new PDF (); // create a new FPDF object
$ Pdf-> AddGBFont (); // set the Chinese font
$ Pdf-> Open (); // start to create a PDF
$ Pdf-> AddPage (); // add a page
$ Pdf-> SetFont ('GB', '', 10); // set the font style
$ Header = array ('product number', 'product name', 'product type', 'product price'); // Set the header
$ Width = array (20, 80, 40, 20); // you can specify the width of each column.
For ($ I = 0; $ I $ Pdf-> Cell ($ width [$ I], 6, $ header [$ I], 1 );
$ Pdf-> Ln ();
Do // circular output table body
{
$ Pdf-> Cell ($ width [0], 6, $ row_rs_prod ['prod _ id'], 1 );
$ Pdf-> Cell ($ width [1], 6, $ row_rs_prod ['prod _ name'], 1 );
$ Pdf-> Cell ($ width [2], 6, $ row_rs_prod ['prod _ type'], 1 );
$ Pdf-> Cell ($ width [3], 6, $ row_rs_prod ['prod _ price'], 1 );
$ Pdf-> Ln ();
} While ($ row_rs_prod = mysql_fetch_assoc ($ rs_prod ));
$ Pdf-> Output ("productworkflow", true); // download a pdf file
?>
The code is as follows:
Define ('fpdf _ fontpath', 'font/'); // defines the path of the font folder
Require_once ('fpdf/fpdf. php'); // contains the fpdf class library file
$ Pdf = new FPDF ('P', 'mm', 'A4 '); // create a new FPDF object, which is placed vertically in millimeters and A4 paper size.
$ Pdf-> Open (); // start to create a PDF
$ Pdf-> AddPage (); // add a page
$ Pdf-> SetFont ('courier ',' I ', 20); // set the font style
$ Pdf-> Cell (0, 0, 'Hello World! '); // Add a cell
$ Pdf-> Output (); // Output PDF to the browser
?>
The code is as follows:
Define ('fpdf _ fontpath', 'font/'); // defines the path of the font folder
Require_once ('fpdf/fpdf. php'); // contains the fpdf class library file
$ Pdf = new FPDF ('P', 'mm', 'A4 '); // create a new FPDF object, which is placed vertically in millimeters and A4 paper size.
$ Pdf-> Open (); // start to create a PDF
$ Pdf-> AddPage (); // add a page
$ Pdf-> SetFont ('courier ',' I ', 20); // set the font style
$ Pdf-> Image('sight.jpg ',); // add an image with the file name sight.jpg
$ Pdf-> Output (); // Output PDF to the browser
?>
The code is as follows:
Define ('fpdf _ fontpath', 'font/'); // defines the path of the font folder
Require_once ('fpdf/fpdf. php'); // contains the fpdf class library file
$ Pdf = new FPDF ('P', 'mm', 'A4 '); // create a new FPDF object, which is placed vertically in millimeters and A4 paper size.
$ Pdf-> Open (); // start to create a PDF
$ Pdf-> AddPage (); // add a page
$ Pdf-> SetFont ('courier ',' I ', 20); // set the font style
$ Pdf-> Cell (60, 10, 'Hello World! ', 1); // add a cell border to 1
$ Pdf-> Output (); // Output PDF to the browser
?>
The code is as follows:
Define ('fpdf _ fontpath', 'font/'); // defines the path of the font folder
Require_once ('fpdf/fpdf. php'); // contains the fpdf class library file
$ Pdf = new FPDF ('P', 'mm', 'A4 '); // create a new FPDF object, which is placed vertically in millimeters and A4 paper size.
$ Pdf-> Open (); // start to create a PDF
$ Pdf-> AddPage (); // add a page
$ Pdf-> SetFont ('arial', '', 14); // set the font style
$ Header = array ('name', 'age', 'sex', 'salary '); // Set the header
$ Data = array (); // sets the table body.
$ Data [0] = array ('Simon ', '24', 'male', '123 ');
$ Data [1] = array ('elastic', '25', 'female ', '123 ');
$ Data [2] = array ('Susan ', '25', 'female', '123 ');
$ Data [3] = array ('David', '26', 'male', '123 ');
$ Width = array (40, 40, 40, 40); // you can specify the width of each column.
For ($ I = 0; $ I $ Pdf-> Cell ($ width [$ I], 6, $ header [$ I], 1 );
$ Pdf-> Ln ();
Foreach ($ data as $ row) // cyclically output table body
{
$ Pdf-> Cell ($ width [0], 6, $ row [0], 1 );
$ Pdf-> Cell ($ width [1], 6, $ row [1], 1 );
$ Pdf-> Cell ($ width [2], 6, $ row [2], 1 );
$ Pdf-> Cell ($ width [3], 6, $ row [3], 1 );
$ Pdf-> Ln ();
}
$ Pdf-> Output (); // Output PDF to the browser
?>
The code is as follows:
Define ('fpdf _ fontpath', 'font/'); // defines the path of the font folder
Require_once ('fpdf/fpdf. php'); // contains the fpdf class library file
$ Pdf = new FPDF ('P', 'mm', 'A4 '); // create a new FPDF object, which is placed vertically in millimeters and A4 paper size.
$ Pdf-> Open (); // start to create a PDF
$ Pdf-> AddPage (); // add a page
$ Pdf-> SetFont ('courier ',' I ', 20); // set the font style
$ Pdf-> Cell (0, 0, 'Hello, FPDF '); // add a Cell and output Chinese characters
$ Pdf-> Output (); // Output PDF to the browser
?>
The code is as follows:
Require ('Chinese. php ');
Class PDF extends pai_chinese
{
Function Header () // Set the Header
{
$ This-> SetFont ('GB', '', 10 );
$ This-> Write (10, 'fpdf Chinese test ');
$ This-> Ln (20 );
}
Function Footer () // Set the Footer
{
$ This-> SetY (-15 );
$ This-> SetFont ('GB', '', 10 );
$ This-> Cell (, 'quarter '. $ this-> PageNo (). 'page ');
}
}
$ Pdf = new PDF (); // create a PDF document
$ Pdf-> AddGBFont ();
$ Pdf-> Open ();
$ Pdf-> AliasNbPages ();
$ Pdf-> AddPage ();
$ Pdf-> SetFont ('GB', 'I', 20 );
$ Pdf-> Cell (, 'Hello, FPDF '); // output a Chinese text
$ Pdf-> Output ();
?>
The code is as follows:
$ Conn = mysql_connect ("localhost", "root", ""); // connect to the database
$ Colname_rs_article = $ _ GET ['id']; // GET the parameter id
Mysql_select_db ("cms", $ conn); // execute SQL
$ Query_rs_article = sprintf ("SELECT * FROM articles WHERE article_id = % s", $ colname_rs_article );
$ Rs_article = mysql_query ($ query_rs_article, $ conn) or die (mysql_error ());
$ Row_rs_article = mysql_fetch_assoc ($ rs_article );
$ TotalRows_rs_article = mysql_num_rows ($ rs_article );
Function conv ($ Text) // process the returned Text
{
$ Text = htmlspecialchars ($ Text); // Convert HTML key characters
$ Text = nl2br ($ Text); // converts line breaks.
Return $ Text;
}
?>
| "> Download PDF document
The code is as follows:
Require ('Chinese. php ');
Class PDF extends pai_chinese
{
Function Header () // Set the Header
{
$ This-> SetFont ('GB', '', 10 );
$ This-> Write (10, 'Article system-XX website ');
$ This-> Ln (20); // line feed
}
Function Footer () // sets the Footer.
{
$ This-> SetY (-15 );
$ This-> SetFont ('GB', '', 10 );
$ This-> Cell (, 'quarter '. $ this-> PageNo (). 'page ');
}
}
// Start the main program
$ Conn = mysql_connect ("localhost", "root", ""); // connect to the database
$ Colname_rs_article = $ _ GET ['id']; // GET the parameter id
Mysql_select_db ("cms", $ conn); // execute SQL
$ Query_rs_article = sprintf ("SELECT * FROM articles WHERE article_id = % s", $ colname_rs_article );
$ Rs_article = mysql_query ($ query_rs_article, $ conn) or die (mysql_error ());
$ Row_rs_article = mysql_fetch_assoc ($ rs_article );
$ TotalRows_rs_article = mysql_num_rows ($ rs_article );
// Start creating a PDF document
$ Pdf = new PDF ();
$ Pdf-> AddGBFont ();
$ Pdf-> Open ();
$ Pdf-> AliasNbPages ();
$ Pdf-> AddPage ();
$ Pdf-> SetFont ('GB', 'B', 20 );
$ Pdf-> Cell (, $ row_rs_article ['title']); // output the article title
$ Pdf-> Ln (); // line feed
$ Pdf-> SetFont ('GB', '', 10 );
$ Pdf-> Cell (, $ row_rs_article ['author']); // output the author
$ Pdf-> Ln ();
$ Pdf-> SetFont ('GB', '', 12 );
$ Content = $ row_rs_article ['content'];
While ($ content! = "") // Cyclically write the document content to the PDF page by page
{
$ Length = strlen ($ content); // get the article length
$ Output = substr ($ content, 0, 1024); // Obtain the output content on this page. each 1024 characters is one page.
$ Pdf-> Cell (, $ output); // output the article content
$ Content = substr ($ content, 1024, $ length); // Obtain the remaining unoutput content
$ Pdf-> AddPage (); // page feed
}
$ Pdf-> Output ($ row_rs_article ['title']. ". pdf", true); // Output a pdf file named as the document title
?>
The code is as follows:
Define ('fpdf _ fontpath', 'font/'); // defines the path of the font folder
Require_once ('fpdf/fpdf. php'); // contains the fpdf class library file
Class PDF extends FPDF
{
Function Header () // Set the Header
{
$ This-> SetFont ('arial', 'B', 15); // Set the header font
$ This-> Cell (80); // Move the Cell
$ This-> Cell (, 'title'); // write header text
$ This-> Ln (20); // line feed
}
Function Footer () // sets the Footer.
{
$ This-> SetY (-15); // you can specify the footer location.
$ This-> SetFont ('arial', 'I', 8); // you can specify the footer font.
$ This-> Cell (, 'page-'. $ this-> PageNo (); // output the current Page number as the footer content
}
}
$ Pdf = new PDF ('P', 'mm', 'A4 '); // create a new FPDF object, which is placed vertically in millimeters and A4 paper size.
$ Pdf-> Open (); // start to create a PDF
$ Pdf-> AddPage (); // add a page
$ Pdf-> SetFont ('courier ',' I ', 20); // set the font style
$ Pdf-> Cell (0, 0, 'Hello World! '); // Add a cell
$ Pdf-> Output (); // Output PDF to the browser
?>