PHP Dynamic PDF Files Tutorial using fpdf

Today, We want to share with you PHP Dynamic PDF Files Tutorial using fpdf.In this post we will show you Creating Dynamic PDF files using HTML and PHP, hear for How to convert your html page to pdf using fpdf in PHP we will give you demo and example for implement.In this post, we will learn about Creating Dynamic PDF files using HTML and PHP with an example.

PHP Dynamic PDF Files Tutorial using fpdf

There are the Following The simple About PHP Dynamic PDF Files Tutorial using fpdf Full Information With Example and source code.

As I will cover this Post with live Working example to develop Php convert html to pdf using fpdf, so the some php code to generate pdf file for this example is following below.

First of all We have to simple Some PHP download fpdf external library as well as requirec this include it in your main PHP file like as a createpdf.php below configuration and how to display tags, headers, fonts as well as images in your main pdf file with format.

Also Read :  FPDF generate PDF Files using PHP dynamically Step By Step

Step 1: HTML Interface

index.html

<html>
<head>
<link href="admin/css/bootstrap.min.css" rel="stylesheet" media="screen">
<link href="admin/css/bootstrap-responsive.min.css" rel="stylesheet" media="screen">
<script type="text/javascript" src="admin/js/jquery-1.8.0.min.js"></script>
<script type="text/javascript" src="admin/js/bootstrap.min.js"></script>
<title>How to create Contact Form using Bootstrap  | Pakainfo.com</title>
</head>

<body>
<h2>PHP create Contact Form using Bootstrap example. => <a href="https://pakainfo.com/">Home</a> | <a href="https://pakainfo.com/">More Demos</a></h2>
<div class="container">
      <form class="contact-us form-horizontal" action="createpdf.php" method="post">
        <legend>PHP Dynamic PDF Files Tutorial using fpdf</legend>        
        <div class="pakainfo control-group gst">
            <label class="control-label live">Name</label>
            <div class="data frm controls">
                <div class="input-prepend">
                <span class="add-on"><i class="icon-user"></i></span>
                    <input type="text" class="input-xlarge" name="name" placeholder="Members Name">
                </div>
            </div>
        </div>
        <div class="pakainfo control-group gst">
            <label class="control-label live">Email</label>
            <div class="data frm controls">
                <div class="input-prepend">
                <span class="add-on"><i class="icon-envelope"></i></span>
                    <input type="text" class="input-xlarge" name="email" placeholder="Members Email">
                </div>
            </div>    
        </div>
        <div class="pakainfo control-group gst">
            <label class="control-label live">Website Url</label>
            <div class="data frm controls">
                <div class="input-prepend">
                <span class="add-on"><i class="icon-globe"></i></span>
                    <input type="text" id="url" class="input-xlarge" name="url" placeholder="https://www.pakainfo.com">
                </div>
            </div>
        </div>
        <div class="pakainfo control-group gst">
            <label class="control-label live">Message</label>
            <div class="data frm controls">
                <div class="input-prepend">
                <span class="add-on"><i class="icon-pencil"></i></span>
                    <textarea name="message" class="span4" rows="4" cols="80" placeholder="Message (Max 200 characters)"></textarea>
                </div>
            </div>
        </div>
        <div class="pakainfo control-group gst">
          <div class="data frm controls">
            <button type="submit" class="btn btn-primary">Submit</button>
            <button type="button" class="btn">Cancel</button>
          </div>    
        </div>
      </form>
</div>
</body>
</html>

Step 2: PHP code to generate pdf file

createpdf.php

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

$pdf=new PDF_HTML();

$pdf->AliasNbPages();
$pdf->SetAutoPageBreak(true, 15);

$pdf->AddPage();
$pdf->Image('logo.png',18,13,33);
$pdf->SetFont('Arial','B',14);
$pdf->WriteHTML('<para><h1>Pakainfo is the most popular Programming & Web Development blog.</h1><br>
Website: <u>www.pakainfo.com</u></para><br><br>Our mission is to provide the best online resources on programming and web development. We deliver the useful and best tutorials for web professionals — developers, programmers, freelancers and site owners. Any visitors of this site are free to browse our tutorials, live demos and download scripts.');

$pdf->SetFont('Arial','B',7); 
$allDataHtmlTable='<TABLE>
<TR>
<TD>Name:</TD>
<TD>'.$_POST['name'].'</TD>
</TR>
<TR>
<TD>Email:</TD>
<TD>'.$_POST['email'].'</TD>
</TR>
<TR>
<TD>Website URl:</TD>
<TD>'.$_POST['url'].'</TD>
</TR>
<TR>
<TD>Message:</TD>
<TD>'.$_POST['message'].'</TD>
</TR>
</TABLE>';
$pdf->WriteHTML2("<br><br><br>$allDataHtmlTable");
$pdf->SetFont('Arial','B',6);
$pdf->Output(); 
?>

Header logo & PDF Set Fonts

Include a Header logo as well as some select font size for main PDF heading.

Also Read :  javascript validation registration form

$pdf->Image('pakainf_logo.png',18,13,33);
$pdf->SetFont('Arial','B',18);

Change Fonts

Select small font and then MAin heading for Data content.

$pdf->SetFont('Arial','B',7);

Convert HTML To PDF

here this source code HTML to pdf file with output

$pdf->WriteHTML2("<br><br><br>$allDataHtmlTable");
$pdf->Output();

Angular 6 CRUD Operations Application Tutorials

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about PHP Dynamic PDF Files Tutorial using fpdf.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Recommended For You.

Ajax Dynamic Dependent Dropdown using Laravel Example
Today, We want to share with you Ajax Dynamic Dependent Dropdown using Laravel Example.In this post we will show you

Add a Comment

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