JPG to PDF Convert PHP Code with HTML and Bootstrap - Full Example
Are you looking for a simple way to convert JPG to PDF using PHP? In this article, you’ll find a complete working solution using PHP, HTML, and Bootstrap. Whether you're building a document conversion tool or just exploring how to convert image files into PDF format in PHP, this tutorial will help you step by step.
✅ Features of This JPG to PDF Converter
-
Upload JPG file
-
Convert it into PDF
-
Bootstrap UI for mobile-friendly design
-
Easy-to-use PHP backend with FPDF library
🧑💻 Requirements
-
PHP 7 or above
-
Apache/Nginx server (or use XAMPP/WAMP)
-
FPDF Library (free and open-source)
📁 Folder Structure
🔔 Note: Download FPDF library from https://www.fpdf.org/ and place
fpdf.php
insidefpdf/
folder.
🧩 Step 1: Create index.php
(HTML Form with Bootstrap)
🧩 Step 2: Create convert.php
(PHP Conversion Code)
💡 How It Works
-
User uploads a
.jpg
file through the HTML form. -
PHP script (
convert.php
) receives the image. -
FPDF generates a PDF file with the image centered on an A4 page.
-
PDF file is downloaded automatically.
📦 Download FPDF Library
Download FPDF from:
👉 https://www.fpdf.org/en/download.php
Unzip and place the fpdf.php
file inside a folder named fpdf/
.