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).
require('./fpdf/fpdf.php');//Include pdf file
2. Then we define an array. The content of the array is today’s medal situation
/*
* country, country
* nationalFlag, national flag
*glod,number of gold medals
* silver, number of silver medals
* copper, number of silver medals
*/
$platle=array(
array('country'=>'PRC','nationalFlag'=>'rpc.jpg','glod'=>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 in the class, let’s define a class ourselves to facilitate defining our own content
class PDF extends FPDF{
/*
* $count,country
* $nationalFlag, the picture address of the flag
* $imageX, x coordinate of the flag
* $imageY, Y coordinate of the flag
* $goldTotal, total number of gold medals
* $silverTotal, total number of silver medals
* $copperTotal, total number of bronze medals
*/
function createHead($country,$nationalFlag,$imageX,$imageY,$goldTotal,$silverTotal,$copperTotal){
$this->setFont('Arial','B','24');//Define a font and style
$this->cell(40,20,$country,15);//Display information about each country
$this->image($nationalFlag,$imageX,$imageY);//The position of the flag
$this->setX('70');//Set the coordinates of the flag
$this->setTextColor(200,160,12);//Set the color of the gold medal
$this->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->cell(40,20,$silverTotal);//Display the number of silver medals
$this->setX('130');//Set the display position of the number of silver medals
$this->setTextColor(187,120,68);//Set the color of the bronze medal
$this->cell(40,20,$copperTotal);//Display the position of the silver medal
$this->ln();//Wrap line
$this->setTextColor(0,0,0); //Because the set color can be effective on the entire page, the initial color will be restored every time you enter a country's information
}
}
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
$pdf=new PDF();//instantiation 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. 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

计算机编程中常见的if语句是条件判断语句。if语句是一种选择分支结构,它是依据明确的条件选择选择执行路径,而不是严格按照顺序执行,在编程实际运用中要根据程序流程选择适合的分支语句,它是依照条件的结果改变执行的程序;if语句的简单语法“if(条件表达式){// 要执行的代码;}”。

Apple在周二推出了iOS17.4更新,为iPhone带来了一系列新功能和修复。这次更新包括了全新的表情符号,同时欧盟用户也能够下载其他应用商店。此外,更新还加强了对iPhone安全性的控制,引入了更多的「失窃设备保护」设置选项,为用户提供更多选择和保障。"iOS17.3首次引入了“失窃设备保护”功能,为用户的敏感资料增加了额外的安全保障。当用户不在家等熟悉地点时,该功能要求用户首次输入生物特征信息,并在一小时后再次输入信息才能访问和更改某些数据,如修改AppleID密码或关闭失窃设备保护功能

前言本文继续来介绍Python集合模块,这次主要简明扼要的介绍其内的命名元组,即namedtuple的使用。闲话少叙,我们开始——记得点赞、关注和转发哦~ ^_^创建命名元组Python集合中的命名元组类namedTuples为元组中的每个位置赋予意义,并增强代码的可读性和描述性。它们可以在任何使用常规元组的地方使用,且增加了通过名称而不是位置索引方式访问字段的能力。其来自Python内置模块collections。其使用的常规语法方式为:import collections XxNamedT

作为一门高效的编程语言,Go在图像处理领域也有着不错的表现。虽然Go本身的标准库中没有提供专门的图像处理相关的API,但是有一些优秀的第三方库可以供我们使用,比如GoCV、ImageMagick和GraphicsMagick等。本文将重点介绍使用GoCV进行图像处理的方法。GoCV是一个高度依赖于OpenCV的Go语言绑定库,其

随着PHP8.0的发布,DOMDocument作为PHP内置的XML解析库,也有了新的变化和增强。DOMDocument在PHP中的重要性不言而喻,尤其在处理XML文档方面,它的功能十分强大,而且使用起来也十分简单。本文将介绍PHP8.0中DOMDocument的新特性和应用。一、DOMDocument概述DOM(DocumentObjectModel)

Python 中的 main 函数充当程序的执行点,在 Python 编程中定义 main 函数是启动程序执行的必要条件,不过它仅在程序直接运行时才执行,而在作为模块导入时不会执行。要了解有关 Python main 函数的更多信息,我们将从如下几点逐步学习:什么是 Python 函数Python 中 main 函数的功能是什么一个基本的 Python main() 是怎样的Python 执行模式Let’s get started什么是 Python 函数相信很多小伙伴对函数都不陌生了,函数是可

两年多前,Adobe 发布了一则引人关注的公告 —— 将在 2020 年 12 月 31 日终止支持 Flash,宣告了一个时代的结束。一晃两年过去了,Adobe 早已从官方网站中删除了 Flash Player 早期版本的所有存档,并阻止基于 Flash 的内容运行。微软也已经终止对 Adobe Flash Player 的支持,并禁止其在任何 Microsoft 浏览器上运行。Adobe Flash Player 组件于 2021 年 7 月通过 Windows 更新永久删除。当 Flash

学编程任何年龄都适合,没有年龄限制。学编程什么年龄都可以学,都适合学,无论你是零基础还是有基础,只要选对合适的编程课程,不管什么年龄都能学会;想做的事情就去做,不要因为过多的担忧而放弃改变,否则错失机会,只会导致更多遗憾。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version
Visual web development tools

Notepad++7.3.1
Easy-to-use and free code editor

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft
