Knowledge Base Hub

Browse through our helpful how-to guides to get the fastest solutions to your technical issues.

Home  >  How-Tos  >  Learn to Generate PDF Files with PHP
Top Scroll

Learn to Generate PDF Files with PHP

 2 min

FPDF, a PHP class, enables you to generate PDF files, and doesn’t depend on additional PHP libraries.

Available for free, it can be downloaded from its official website’s download section. Its download package comprises of all the essential files as well as some tutorials on using it.

The package can be uploaded on your MilesWeb account using FTP, or using File Manager in cPanel and extracted it after that. Then place the extracted contents in any folder on your account, which will then get converted into the FPDF installation folder.

The basic example of using FPDF is by using the below PHP code (you should select the FPDF package in the folder where the PHP file with the code is placed):

<?php
require(‘./fpdf.php’);

$pdf=new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output();
?>

Suppose you have downloaded and extracted the FPDF package within a folder called ~/public_html/fpdf/.

Additionally, you can create a new PHP file called toPDF.php within the same folder and insert the above code. Then save the file and try accessing it through your browser:

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

After the execution, the PHP script will generate a PDF file in your browser.

For our Knowledge Base visitors only
Get 10% OFF on Hosting
Special Offer!
30
MINS
59
SECS
Claim the discount before it’s too late. Use the coupon code:
STORYSAVER
Note: Copy the coupon code and apply it on checkout.