Posted inProgramming / Mysql / Mysqli / php

Creating PDF Files using PHP FPDF library – Convert HTML to PDF

Creating PDF Files using PHP FPDF library – Convert HTML to PDF

In this Post We Will Explain About is Creating PDF Files using PHP FPDF library – Convert HTML to PDF With Example and Demo.

Welcome on Pakainfo.com – Examples ,The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to fpdf – How to create a pdf file from an HTML using php

In this post we will show you Best way to implement php – how to generate pdf and save to server, hear for How to How to Convert HTML to PDF in PHP with fpdf with Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

FPDF Basics

Basic Example of the php – how to generate pdf and save to server

AddPage();
$livepdf->SetFont('Arial','B',16);
$livepdf->Cell(40,10,'welcome to Pakainfo.com!');
$livepdf->Output();
?>

Generate PDF from MySQL Data using FPDF

$livepdf = new FPDF(); //simple default
//Live24u learn to OR with settings simple Like as a : FPDF('orientation','unit','size');
//Live24u learn to Orientation simple  Like as a-- P or Portrait & L or Landscape
//Live24u learn to Unit simple Like as a --pt: point, mm: millimeter, cm: centimeter, in: inch
//Live24u learn to Size simple Like as a-- A3, A4, A5, Letter, Legal
$livepdf = new FPDF('P','mm','A4');
$livepdf->SetFont('Arial','B',16);
$livepdf->Cell(40,10,'Hello World !',1);

Add a new simple cell next to it with centered text and go to the next line

$livepdf->Cell(60,10,'Powered by FPDF.',0,1,'C');

we send PDF output to the browser or file

$livepdf->Output(); //default output to browser

//PDF output settings
//Pakainfo.com - > I: to the browser.
//Pakainfo.com - > D: force a file download
//Pakainfo.com - > F: save to a local file
//Pakainfo.com - > S: return the document as a string. name is ignored.
$livepdf->Output('sara.pdf', 'D'); //force download file

PDF with line breaks

specify width and height as well as line breaks of the cell Multicell(width, height, string) syntxt.

AddPage();
$livepdf->SetFont('Arial','B',16);

$livepdf->Multicell(190,10,$the_content);

$livepdf->Output();

?>

Create PDF from a URL

we can easily simple create PDF file some from a URL, we need to simple call or play a bit with PHP HTML DOM or we can use Simple HTML data DOM Parser for that some matter, have a simple look at the source code below.

loadHTML($content);

$text_for_pdf = $doc->getElementById('page_content')->nodeValue;

$livepdf = new FPDF();
$livepdf->AddPage();
$livepdf->SetFont('Arial','B',12);

$livepdf->Multicell(190,10, $text_for_pdf);

$livepdf->Output();
?>

Example

I hope you have Got fpdf – How to create a pdf file from an HTML using php And how it works.I would Like to have FeadBack From My Blog(Pakainfo.com) readers.Your Valuable FeadBack,Any Question,or any Comments abaout This Article(Pakainfo.com) Are Most Always Welcome.

I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.

Leave a Reply

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

We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype