PHP does not provide a native library for generating PDF files, instead of that they offer an external PHP extension called PDFlib. You can find the library documentation here. A big drawback of this tool is that the full package is not available as open source, only a Lite version of it that supports only a subset of it’s functionality.
Using PDFlib is pretty straight forward, you can check out a couple of examples here
I’m going to give you a different alternative to work with, it’s called FPDF. This PHP class is a great tool for us as developers, as it allows us to generate PDF files directly from PHP, without the need of using the PDFlib library.
The main advantage of this piece of code is that you can use it without any restrictions.
FPDF is a very good choice if you want to be able to create more complex PDF files, however the performance of the class is not as good as the performance of the library, when you want to create large documents.
Here is the most basic example of how to use FPDF:
<?phprequire('fpdf.php');$pdf = new FPDF();$pdf->AddPage();$pdf->SetFont('Arial','B',16);$pdf->Cell(40,10,'Hello World!');$pdf->Output();
For more examples and documentation go to the project’s page