How to generate PDF files with PHP?

FPDF is a PHP class that allows you to generate PDF files without using the PDFlib library.

FPDF is free and can be downloaded from the official website’s download section. The download package contains all necessary files, along with some tutorials on how to use it.

A basic example of using FPDF is with the following PHP code (you must download and extract the FPDF package in the folder where the PHP file with the code is located):

 

 

Let's say that you have downloaded and extracted the FPDF package inside a folder called ~/public_html/fpdf/. You can create a new PHP file called toPDF.php inside the same folder and insert the above code. You can then save the file and try to access it through your browser:

http://yourdomainname.com/fpdf/toPDF.php

Upon execution of the script, a new PDF file will be generated and you will be prompted to download it.

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

Does Hostlantern support PHP HTTP Authorization?

Hostlantern supports the PHP HTTP Authorization and in order to enable it you need to add the...

Is PHP Safe Mode turned Off on Hostlantern’s servers

PHP Safe Mode is by default turned off for all PHP versions available on Hostlantern servers....

How to enable zlib compression manually for PHP scripts

PHP Zlib module allows you to transparently read and write gzip compressed files. Thus it is used...

What is SourceGuardian and how to use it?

SourceGuardian is commercial software which allows you to securely encode, compile and encrypt...

How to install Smarty Template Engine

Follow the steps below to install Smarty Template Engine on your hosting account: Download the...