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.


Related FAQ

Here are some more FAQ related to this Article:

  1.   Laravel Toggle Switch Inside Bootstrap Ajax Example
  2.   Ajax Image Upload using PHP and jQuery
  3.   Laravel Vue JS ajax file upload multipart form data
  4.   Redirect page after delay using Laravel Example
  5.   AngularJS Login Script using PHP MySQL
  6.   PHP Create PDF file using mpdf | tcpdf | fpdf | php html to pdf
  7.   laravel 6 auth
  8.   Angular 6 - User Registration and Login Example & Tutorial
  9.   FPDF generate PDF Files using PHP dynamically Step By Step
  10.   How To Create Contact Form With PHPMailer To Send Mails