Introduction
PDF stands for Portable Document File
How to create Pdf documents in PHP
PHP is one of the most popular backend scripting languages, with more than 70% of Entire Websites built on it.
To create pdf documents, we’ll use the pdf creation library fpdf
Download & Extract FPDF library
Go to the official website of FPDF & download the zip in your preferred language.
Basic Hello World Example
Create a file hello-world.php and add the following code to it-
<?php
require('fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output();
?>
When you run the above code, pdf file with hello world text will be downloaded.
Adding Image to PDF with FPDF
You can also add images in your pdf file, just use the code below-
// Insert a logo in the top-left corner at 300 dpi by passing relative url of file
$pdf->Image('logo.png',10,10,-300);
// Insert a dynamic image from a URL
$pdf->Image('http://chart.googleapis.com/chart?cht=p3&chd=t:60,40&chs=250x100&chl=Hello|World',60,30,90,0,'PNG');