PHP 8 Create PDF File From HTML Form Using Fpdf Example

To create a pdf from a form using php. In this tutorial, you will learn how generate a pdf file using fpdf in php.

Sometimes, you need to generate a pdf file from html forms and want to store in your php app.

So, this tutorial will guide you step by step on how to create pdf file using the 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

We create websites that stand-out in the crowd by making the optimum use of the WordPress features.


Company Name