Security, Tech & Programming
Best PHP PDF Library without composer

Best PHP PDF Library without composer

You can use the pdf library DomPDF without using composer. Actually the library installation dues support composer too, but they provide normal releases on their official github repo which does not require composer.

How to install DOMPDF without composer

Simply goto:

https://github.com/dompdf/dompdf

Then goto releases and download the latest release.

Unzip the downloaded files in your projects subfolder, then point to the autoload file inside of it. Your basic hello world code with dompdf would look like this:

<?php
require_once 'dompdf/autoload.inc.php';

// reference the Dompdf namespace
use Dompdf\Dompdf;

// instantiate and use the dompdf class
$dompdf = new Dompdf();
$dompdf->loadHtml('hello world');

// Render the HTML as PDF
$dompdf->render();

// Output the generated PDF to Browser
$dompdf->stream();

Once you get the hello world example working, then you can pass in your custom html to the loadHtml method of dompdf to print that as the pdf file.

How to give name to pdf file in dompdf

To give custom name to the generated pdf file, simply pass in the filename to the stream method instead of leaving it blank.

So the code will look like this:

$dompdf->stream('filename.pdf');

Does DomPDF support flex and grid?

No. Dompdf does not support flex or grid.

Leave a Reply

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

Hire Me!