Top 5 Best php PDF Generation libraries

Top 5 Best php PDF Generation libraries

Today, We want to share with you Top 5 Best php PDF Generation libraries.In this post we will show you generate pdf file in php Source code, hear for Best open source PDF generation libraries for PHP we will give you demo and example for implement.In this post, we will learn about PDF generation libraries : open source PDF generation libraries -PHP with an example.

Top 5 Best php PDF Generation libraries

There are the Following The simple About Top 5 Best php PDF Generation libraries Full Information With Example and source code.

  PHP Magento extension soap must be loaded error

As I will cover this Post with live Working example to develop Top 5 : Best open source PDF generation libraries for PHP, so the some major fpdf, mpdf php, tcpdf for this example is following below.

There are The List of the best php pdf libraries Like as a (FPDF, )

5. FPDF

generate pdf file in php code

A basic example of using PHP FPDF is with the following PHP source code (you must simple extract the FPDF libraries package in the directory where FPDF the PHP file with the source code is located):

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

$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',20);
$pdf->Cell(50,10,'Pakainfo.com!');
$pdf->Output();
?>

Create PDF file with PHP using FPDF

best php pdf library

<?php
require('classes/fpdf/fpdf.php'); 
class PDF extends FPDF {
 
function Header() {
    $this->SetFont('Times','',12);
    $this->SetY(0.25);
    $this->Cell(0, .25, "Jaydeep Gondaliya ".$this->PageNo(), 'T', 2, "R");
    //reset Y
    $this->SetY(1);
}
 
function Footer() {
    $this->Image("pakainfo_logo.jpg", (8.5/2)-1.5, 9.8, 3, 1, "JPG", "https://www.pakainfo.com");
}
 
}
 
$pdf=new PDF("P","in","Letter");
 
$pdf->SetMargins(1,1,1);
 
$pdf->AddPage();
$pdf->SetFont('Times','',12);
 
$paragraph1=".";
$paragraph2=".";
$paragraph3 =".";
  
$pdf->SetFillColor(240, 100, 100);
$pdf->SetFont('Times','BU',12);
  
$pdf->Cell(0, .25, "paragraph", 1, 2, "C", 1);
  
$pdf->SetFont('Times','',12);
$pdf->MultiCell(0, 0.5, $paragraph1, 'LR', "L");
$pdf->MultiCell(0, 0.25, $paragraph2, 1, "R");
$pdf->MultiCell(0, 0.15, $paragraph3, 'B', "J");
 
$pdf->AddPage();
$pdf->Write(0.5, $paragraph1.$paragraph2.$paragraph3);
  
$pdf->Output();
?>

4. mPDF

mPDF

<?php
require_once __DIR__ . '/vendor/autoload.php';

$mpdf = new mPDF();

$mpdf->WriteHTML('<h1>Welcome To Pakainfo.com</h1><br><p>My first Pakainfo Blogs PDF with mPDF From Jaydeep Gondaliya</p>');

$mpdf->Output();
?>

3. DOMPDF

DOMPDF

<?php
require_once 'dompdf/autoload.inc.php';
use Dompdf\Dompdf;

$dompdf = new Dompdf();
$dompdf->loadHtml('<h1>Welcome To Pakainfo.com Demo</h1><br><p>Jaydeep Gondaliya!</p>');

$dompdf->setPaper('A4', 'portrait');

$dompdf->render();

$dompdf->stream();

2. Snappy (wkhtmltopdf)

Snappy

<?php

require __DIR__ . '/vendor/autoload.php';

use Knp\Snappy\Pdf;

$snappy = new Pdf('wkhtmltopdf.exe');
header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename="myfile.pdf"');
echo $snappy->getOutput('https://www.pakainfo.com');

1. TCPDF

generate pdf in php example
1. TCPDF

<?php 
require_once('tcpdf_include.php');

$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Our Code World');
$pdf->SetTitle('Example Write Html');

$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 006', PDF_HEADER_STRING);

$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);


$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);

$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

$pdf->AddPage();

$html = '<h4>PDF Example</h4><br><p>Welcome to the Pakainfo.com</p>';
 
$pdf->writeHTML($html, true, false, true, false, '');
$pdf->AddPage();

$html = '<h1>Welcome</h1>';
$pdf->writeHTML($html, true, false, true, false, '');

$pdf->lastPage();
$pdf->Output('example_006.pdf', 'I');

Angular 6 CRUD Operations Application Tutorials

Read :

  Simple Print PHP Hello World program From scratch

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Top 5 Best php PDF Generation libraries.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Reply

avatar
  Subscribe  
Notify of