PHP PDF Generation using FPDF

Last modified on February 3rd, 2017 by Vincy.

In this tutorial, we are going to generate PDF from text file data using PHP FPDF library. In this library, there are features to add PDF page, set font, create grid and more.

In this example, we are having a text file containing toys detail. We are reading this file content and show it in PDF format.

View Demo

php_pdf

PHP-FPDF Code for PDF Generation

This code is used to generate PDF for displaying text file data. Download FPDF to execute this script.

<?php
require('fpdf/fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
$row=file('toys.txt');
$pdf->SetFont('Arial','B',12);	
foreach($row as $rowValue) {
	$data=explode(';',$rowValue);
	foreach($data as $columnValue)
		$pdf->Cell(90,12,$columnValue,1);
		$pdf->SetFont('Arial','',12);		
		$pdf->Ln();
}
$pdf->Output();
?>

View DemoDownload

↑ Back to Top

Share this Article