Integrated Tech Solutions

How to Generate PDF Files in PHP [Without Composer]

By - Admin December 5, 2021

Introduction

PDF stands for Portable Document File

In 1991, Adobe co-founder Dr John Warnock launched the paper-to-digital revolution with an idea he called, The Camelot Project. The goal was to enable anyone to capture documents from any application, send electronic versions of these documents anywhere and view and print them on any machine. By 1992, Camelot had developed into PDF. Today, it is the file format trusted by businesses around the world.

Source – Adobe.com

How to create Pdf documents in PHP

PHP is one of the most popular backend scripting languages, with more than 70% of Entire Websites built on it.

To create pdf documents, we’ll use the pdf creation library fpdf

Download & Extract FPDF library

Go to the official website of FPDF & download the zip in your preferred language.

Download FPDF Library

Basic Hello World Example

Create a file hello-world.php and add the following code to it-

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

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

When you run the above code, pdf file with hello world text will be downloaded.

Adding Image to PDF with FPDF

You can also add images in your pdf file, just use the code below-

// Insert a logo in the top-left corner at 300 dpi by passing relative url of file
$pdf->Image('logo.png',10,10,-300);
// Insert a dynamic image from a URL 
$pdf->Image('http://chart.googleapis.com/chart?cht=p3&chd=t:60,40&chs=250x100&chl=Hello|World',60,30,90,0,'PNG');

You May Also Like –

Keep Reading

👋 Hi, Find this Helpful? There is More

You Asked,
We made it!

fix japanese keyword hack

Step by Step Video Tutorials on trending topics in software development

Yes I am Curious »

5 Tips to Pick the Most Engaging Live Chat for Your Website

In today’s fast-paced digital world, providing excellent customer service is a key differentiator for businesses. One of the most effective...

Know More »
next js deployed on aws

Beginners Guide to deploy NextJs App on AWS EC2 Server

In this blog post, we will walk you through the step-by-step process of deploying a Next.js application on an AWS...

Know More »