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).
2. Then we define an array. The content of the array is today’s medal situation
3. Since the first step has been included in the class, let’s define a class ourselves to facilitate defining our own content
Explanation of various methods used:
1. SetFont(string family [, string style [, float size]])
Set the font of the string. The font set by this method is used throughout the PDF file before the text or 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 that 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])
The completion line breaks and wraps. 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])
Defines 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 it
Note:
1. The AddPage() method 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