Home Backend Development PHP Tutorial Teach you step by step to print out PDF (about the simple application of fpdf)_PHP tutorial

Teach you step by step to print out PDF (about the simple application of fpdf)_PHP tutorial

Jul 21, 2016 pm 03:03 PM
class fpdf pdf php about Angel application Hand in hand beat teach you use of Simple this

The class used today is called FPDF. The PHP Class FPDF allows you to use pure PHP (more precisely, without using PDFlib) to generate PDF files. It presents PHP Class and accelerates the processing of PDF documents in programming languages. Its features include: selectable unit size, page format and margins; header and footer management; automatic paging; automatic word wrapping and automatic text alignment, etc. At the same time, it also supports a variety of image formats, such as JPEG, PNG, TrueType and Type1, etc. Give it a try and you won't be disappointed.
1. Download the fpdf class from the Internet, and then include the require utility (also in the attachment).

Copy code The code is as follows:

require('./fpdf/fpdf.php');// Contains pdf files

2. Then we define an array. The content of the array is today’s medal situation.
Copy code The code is as follows:

/*
* country, country
* nationalFlag, national flag
* glod, number of gold medals
* silver, number of silver medals
* copper, number of silver medals
*/ >27,'silver'=>13,'copper'=>15),
array('country'=>'USA','nationalFlag'=>'usa.jpg','glod '=>25,'silver'=>16,'copper'=>4),
array('country'=>'UK','nationalFlag'=>'uk.jpg', 'glod'=>14,'silver'=>7,'copper'=>8)
         );


3. Since the first step has been included The class is here, and then we define a class ourselves to facilitate defining our own content

Copy the code The code is as follows:

class PDF extends FPDF{
* $count,country
$imageY, the Y coordinate of the flag
* $goldTotal, the total number of gold medals
* $silverTotal, the total number of silver medals
,$ image $this->cell(40,20,$country,15);//Display the information of each country
                   $this->image($nationalFlag,$imageX,$imageY);//The position of the flag $ this-& gt; setx ('70 '); // Set the coordinates of the national flag
$ this- & gt; settextColor (200,160,12); // Set the color of the gold medal
$ this- & gt; cell (40,20,$goldTotal);//Display the number of gold medals
$this->setX('100');//Set the display position of the number of gold medals
$this->setTextColor(170,162,138); // Set the color of the silver medal
$ this- & gt; cell (40,20, $ Silvertotal); // Show the number of silver medals
$ This- & GT; setx ('130'); // Set the number of silver medals. Display position
                                                                                      $this-> $this->ln();//Wrap the line
                                                                                                                                                                                                                                                                                ​ The information will restore the initial color
}
}




Explanation of various methods used:


1. SetFont (string family [, string style [, float size]])
Set the font style of the string. The font set by this method is used throughout the PDF file before the text or the entire article is displayed.

Parameter 1: family, set the required font.
Parameter 2: style, set the style. (The empty string represents normal text, U represents underline, B represents bold, and I represents italic).
Parameter 3: size, the size of the font.
2. Cell(float w [, float h [, string txt]])
displays a cell (rectangular range), and also provides other functional options, including (border, background color, string) . The position of the upper left corner of the cell is the current position.
Note: There are other parameters in this method, which are not listed. Because it was not used in this experiment.
Parameter 1: w cell width. If: 0, the cell will extend to the right edge of the page.
Parameter 2: Cell height. The default value is: 0.Parameter 3: txt, the content to be printed.

3. Ln([float h])
Complete line break and line break. This will change the current (x, y) coordinates, move the abscissa (x) back to the left edge, and increase the height of the ordinate (y). Parameter 1: h, the distance or height of the next line. The default value is: the height is equal to the last displayed height.


4. SetTextColor(int r [, int g, int b])
Define the color used for text. Can be defined using RGB color or grayscale modes. This function can be created from one page to another, and that color value will be retained from one page to another.


4. The class has been defined. Finally, call



Copy the code


The code is as follows:


$pdf=new PDF();//Instantiate class
$pdf->AddPage();
$imageX=40;//Set the initial X value of the image
$imageY=15;//Set the initial Y value of the image
foreach($platle as $key=>$value){
$pdf->createHead($value['country'],$value ['nationalFlag'],$imageX,$imageY,$value['glod'],$value['silver'],$value['copper']);
                $imageY+=20; 
   }
$pdf->output();//Output PDF

Note:
1. AddPage() method It is used to generate a new page. Each call generates a new page.
2. The outPut() method is used to output PDF.
Code and class file download: Click to download

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/327856.htmlTechArticleThe class used today is called FPDF. The FPDF PHP Class allows you to use pure PHP (more precisely, no need Use PDFlib) to generate PDF files. It is presented in PHP Class and accelerates the programming of PDF documents...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

To work on file upload we are going to use the form helper. Here, is an example for file upload.

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

In this chapter, we are going to learn the following topics related to routing ?

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

Validator can be created by adding the following two lines in the controller.

See all articles