PHP Fpdf Class Library application implementation Code _php tutorial

Source: Internet
Author: User
Copy CodeThe code is as follows:
Require (' chinese.php ');
Class PDF extends Pdf_chinese
{
function header ()//Set Header
{
$this->setfont (' GB ', ', 10);
$this->write ("XX company product directory");
$this->ln (20); Line break
}
function Footer ()//Set Footer
{
$this->sety (-15);
$this->setfont (' GB ', ', 10);
$this->cell (0,10, ' $this '.->pageno (). ' Page ');
}
}

$conn = mysql_connect ("localhost", "root", ""); Connecting to a 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 Chinese font
$pdf->open (); Start creating PDF
$pdf->addpage (); Add a page

$pdf->setfont (' GB ', ', 10); Set font style

$header =array (' Product number ', ' Product name ', ' Product type ', ' Product Unit price '); Set up the table header
$width =array (20,80,40,20); Set width per column

for ($i =0; $i $pdf->cell ($width [$i],6, $header [$i],1];
$pdf->ln ();

Do//loop 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 ("Product.pdf", true); Download PDF file
?>

Copy CodeThe code is as follows:
Define (' Fpdf_fontpath ', ' font/'); Define 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, put paper vertically, in millimeters, paper size A4
$pdf->open (); Start creating PDF
$pdf->addpage (); Add a page
$pdf->setfont (' Courier ', ' I ', 20); Set font style
$pdf->cell (0,0, ' Hello world! '); Add a cell
$pdf->output (); Output PDF to Browser
?>

Copy CodeThe code is as follows:
Define (' Fpdf_fontpath ', ' font/'); Define 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, put paper vertically, in millimeters, paper size A4
$pdf->open (); Start creating PDF
$pdf->addpage (); Add a page
$pdf->setfont (' Courier ', ' I ', 20); Set font style
$pdf->image (' sight.jpg ', 20,20,0,0); Add an image with the file name Sight.jpg
$pdf->output (); Output PDF to Browser
?>

Copy CodeThe code is as follows:
Define (' Fpdf_fontpath ', ' font/'); Define 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, put paper vertically, in millimeters, paper size A4
$pdf->open (); Start creating PDF
$pdf->addpage (); Add a page
$pdf->setfont (' Courier ', ' I ', 20); Set font style
$pdf->cell (60,10, ' Hello world! ', 1); Add a cell border of 1
$pdf->output (); Output PDF to Browser
?>

Copy CodeThe code is as follows:
Define (' Fpdf_fontpath ', ' font/'); Define 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, put paper vertically, in millimeters, paper size A4
$pdf->open (); Start creating PDF
$pdf->addpage (); Add a page

$pdf->setfont (' Arial ', ', 14); Set font style

$header =array (' Name ', ' age ', ' Sex ', ' Salary '); Set up the table header
$data =array (); Set the body of a table
$data [0] = array (' Simon ', ' n ', ' Male ', ' 5,000.00 ');
$data [1] = array (' Elaine ', ' + ', ' Female ', ' 6,000.00 ');
$data [2] = array (' Susan ', ' + ', ' Female ', ' 7,000.00 ');
$data [3] = array (' David ', ' n ', ' Male ', ' 8,000.00 ');

$width =array (40,40,40,40); Set width per column

for ($i =0; $i $pdf->cell ($width [$i],6, $header [$i],1];
$pdf->ln ();

foreach ($data as $row)//Loop 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 Browser
?>

Copy CodeThe code is as follows:
Define (' Fpdf_fontpath ', ' font/'); Define 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, put paper vertically, in millimeters, paper size A4
$pdf->open (); Start creating PDF
$pdf->addpage (); Add a page
$pdf->setfont (' Courier ', ' I ', 20); Set font style
$pdf->cell (0,0, ' Hello, FPDF '); Add a cell and output the Chinese
$pdf->output (); Output PDF to Browser
?>

Copy CodeThe code is as follows:
Require (' chinese.php ');
Class PDF extends Pdf_chinese
{
function header ()//Set Header
{
$this->setfont (' GB ', ', 10);
$this->write (' fpdf Chinese test ');
$this->ln (20);
}

function Footer ()//Set Footer
{
$this->sety (-15);
$this->setfont (' GB ', ', 10);
$this->cell (0,10, ' $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 (0,10, ' Hello, FPDF '); Output a section of Chinese
$pdf->output ();
?>

Copy CodeThe code is as follows:
$conn = mysql_connect ("localhost", "root", ""); Connecting to a database
$colname _rs_article = $_get[' id ']; Get 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)//handling of returned text
{
$Text =htmlspecialchars ($Text); Converting HTML key characters
$Text =nl2br ($Text); Convert line breaks
return $Text;
}
?>


| "> Download PDF document





Copy CodeThe code is as follows:
Require (' chinese.php ');
Class PDF extends Pdf_chinese
{
function header ()//Set Header
{
$this->setfont (' GB ', ', 10);
$this->write (10, ' article System-XX website ');
$this->ln (20); Line break
}
function Footer ()//Set Footer
{
$this->sety (-15);
$this->setfont (' GB ', ', 10);
$this->cell (0,10, ' $this '.->pageno (). ' Page ');
}
}
Main program Start
$conn = mysql_connect ("localhost", "root", ""); Connecting to a database
$colname _rs_article = $_get[' id ']; Get 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 PDF documents
$pdf =new PDF ();
$pdf->addgbfont ();
$pdf->open ();
$pdf->aliasnbpages ();
$pdf->addpage ();
$pdf->setfont (' GB ', ' B ', 20);
$pdf->cell (0,10, $row _rs_article[' title '); Output article title
$pdf->ln (); Line break
$pdf->setfont (' GB ', ', 10);
$pdf->cell (0,10, $row _rs_article[' author '); Output article author
$pdf->ln ();
$pdf->setfont (' GB ', ', 12);
$content = $row _rs_article[' content '];
while ($content! = "")//loop-by-page writing of article content to PDF
{
$length = strlen ($content); Get article length
$output = substr ($content, 0, 1024); Get output on this page, 1 pages per 1024 characters
$pdf->cell (0,10, $output); Output article content
$content = substr ($content, 1024x768, $length); Get remaining non-output content
$pdf->addpage (); Page change
}
$pdf->output ($row _rs_article[' title '). PDF ", true); Output PDF file, file name is article title
?>

Copy CodeThe code is as follows:
Define (' Fpdf_fontpath ', ' font/'); Define the path of the font folder
Require_once (' fpdf/fpdf.php '); Contains the Fpdf class library file

Class PDF extends FPDF
{
function header ()//Set Header
{
$this->setfont (' Arial ', ' B ', 15); Set the header font
$this->cell (80); Move cells
$this->cell (30,10, ' Title '); Write header text
$this->ln (20); Line break
}

function Footer ()//Set Footer
{
$this->sety (-15); Set the location of your footer
$this->setfont (' Arial ', ' I ', 8); Set Footer Font
$this->cell (0,10, ' Page-'. $this->pageno ()); Output current page number as footer content
}
}

$pdf =new PDF (' P ', ' mm ', ' A4 '); Create a new Fpdf object, put paper vertically, in millimeters, paper size A4
$pdf->open (); Start creating PDF
$pdf->addpage (); Add a page
$pdf->setfont (' Courier ', ' I ', 20); Set font style
$pdf->cell (0,0, ' Hello world! '); Add a cell
$pdf->output (); Output PDF to Browser
?>

http://www.bkjia.com/PHPjc/320045.html www.bkjia.com true http://www.bkjia.com/PHPjc/320045.html techarticle Copy the code as follows: PHP require (' chinese.php '), class PDF extends Pdf_chinese {function header ()//Set Header {$this-setfont (' GB '), ", 10); $this-write, ' xx company product name ...

  • 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.