Php FPDF class library application implementation code

Source: Internet
Author: User

Copy codeThe Code is as follows:
<? Php
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 <count ($ header); $ I ++) // loop output header
$ 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
?>

Copy codeThe Code is as follows:
<? Php
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
?>

Copy codeThe Code is as follows:
<? Php
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
?>

Copy codeThe Code is as follows:
<? Php
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
?>

Copy codeThe Code is as follows:
<? Php
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 <count ($ header); $ I ++) // loop output header
$ 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
?>

Copy codeThe Code is as follows:
<? Php
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
?>

Copy codeThe Code is as follows:
<? Php
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 ();
?>

Copy codeThe Code is as follows:
<? Php
$ 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;
}
?>
<P align = "center"> <B> <? Php echo $ row_rs_article ['title'];?> </B> </p>
<P align = "center"> <font size = 2> <? Php echo $ row_rs_article ['author'];?> | <A href = "showpdf. php? Id = <? Php echo $ row_rs_article ['Article _ id'];?> "> Download PDF documentation </a> </font> </p>
<HR>
<P> <? Php echo conv ($ row_rs_article ['content']);?> </P>

Copy codeThe Code is as follows:
<? Php
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
?>

Copy codeThe Code is as follows:
<? Php
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
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.