How to Create PDF file using fpdf in PHP

I have used a library fpdf open source and very useful library for developers here is a simple tutorial on how to convert How to Convert HTML to PDF with fpdf.

Download fpdf library

With fpdf library we used HTMLparser library contributed by programmers and all other libraries available here you can download and use as per your requirement.

Code

<?php
require('pdf/fpdf.php');

$pdf=new FPDF();

$pdf->SetAuthor('Demo');
$pdf->SetTitle('FPDF tutorial');

$pdf->SetFont('Helvetica','B',20);
$pdf->SetTextColor(50,60,100);

$pdf->AddPage('P');

$pdf->SetXY(50,20);
$pdf->SetDrawColor(50,60,100);
$pdf->Cell(100,10,'FPDF Tutorial',1,0,'C',0);

//Set x and y position for the main text, reduce font size and write content

$pdf->SetXY (10,50);
$pdf->SetFontSize(10);
$pdf->Write(5,'Now your pdf Successfully Create');

//Output the document
$pdf->Output();

?> 

Leave a Reply

Your email address will not be published. Required fields are marked *