PHP 8 Create PDF File From HTML Form Using Fpdf Example

PHP 8 Create PDF File From HTML Form Using Fpdf Example

To generate a pdf file from HTML forms and want to store it in your PHP app, In this tutorial, you will learn how to generate a pdf file using fpdf in php.

How to create PDF file using Fpdf in PHP

Follow following the below steps and upload file using dropzone js and jquery without refreshing the whole web page in PHP:

  • Step 1 – Download fpdf Library
  • Step 2 – Create index.php
  • Step 3 – Create pdf.php

Step 1 – Download fpdf Library

In this step, you need to visit the following link and download the fpdf library.

Note that, Add this library in pdf.php file.

Step 2 – Create index.php

In this step, you need to visit your project directory and create an index.php file. Then add the below HTML code into your index.php file:

<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <title>Simple Registration Form in PHP -</title>
    <link rel="stylesheet" href="">
    <link rel="stylesheet" href="">
    <script src=""></script>
    <script src="[email protected]/dist/umd/popper.min.js"></script>
    <script src=""></script>
    <div class="container">
        <div class="row">
            <div class="col-lg-8 col-offset-2">
                <div class="page-header">
                    <h2>Registration Form in PHP</h2>
                <p>Please fill all fields in the form</p>
                <form action="pdf.php" method="post">
                    <div class="form-group">
                        <input type="text" name="name" class="form-control" value="" maxlength="50" required="">
                    <div class="form-group ">
                        <input type="email" name="email" class="form-control" value="" maxlength="30" required="">
                    <div class="form-group">
                        <input type="text" name="mobile" class="form-control" value="" maxlength="12" required="">
                        <span class="text-danger">
                    <input type="submit" class="btn btn-primary" name="signup" value="submit">

This HTML code shows the registration form.

Step 3 – Create pdf.php

In this step, create a new file name pdf.php file and add the below code into your pdf.php file:

    $name = $_POST['name'];
    $email = $_POST['email'];
    $mobile = $_POST['mobile'];
    $pdf = new FPDF();
    $pdf->Cell(0,10,"Registration Details",1,1,'C');
    $file = time().'.pdf';

The pdf.php file code will create pdf file using fpdf library.


In this tutorial, you have learned how to create PDF file in PHP using fpdf.

Recommended PHP Tutorials


Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

Your email address will not be published. Required fields are marked *