Posts Tagged php 5

Coming Soon - Premium WordPress Theme Giveaway To All Our Email Subscribers

Tutorial on dynamically creating PDF file in websites using PHP

There are many circumstances we come across where we need to create PDF files in our websites dynamically(like creating a PDF file from fetching data from a MySQL database or an external text file).But many don’t have any idea on how to create such PDF files, so I thought it will be a great idea to do a tutorial on this since there aren’t many tutorials on this topic on the web.

When it comes to creating dynamic PDF files in websites, there are two PHP classes available, They are

  • FPDF
Both of them are free and easy to use and below is their description from the official website.

create PDF files in our websites dynamically(like creating a PDF file from fetching data from a MySQL database or an external text file)

What is TCPDF ?

TCPDF is a FLOSS PHP class for generating PDF documents.Started in 2002, TCPDF is now one of the world’s most active Open Source projects, used daily by millions of users and included in thousands of CMS and Web applications.You can generate PDF files for almost any application using TCPDF.

What is FPDF ?

FPDF is a PHP class which allows to generate PDF files with pure PHP, that is to say without using the PDFlib library. F from FPDF stands for Free: you may use it for any kind of usage and modify it to suit your needs.FPDF requires no extension (except zlib to activate compression and GD for GIF support). It works with PHP 4 and PHP 5 (the latest version requires at least PHP 4.3.10).
But due to rich documentation, vast number of examples and an active support forum I prefer TCPDF and I am going to take TCPDF as a base for this tutorial.
Here are a list of some of the features of TCPDF:
  • no external libraries are required for the basic functions;Create PDF files from data from SQL database using TCPDF
  • all standard page formats, custom page formats, custom margins and units of measure;
  • UTF-8 Unicode and Right-To-Left languages;
  • TrueTypeUnicode, OpenTypeUnicode, TrueType, OpenType, Type1 and CID-0 fonts;
  • font subsetting;
  • methods to publish some XHTML + CSS code, JavaScript and Forms;
  • images, graphic (geometric figures) and transformation methods;
  • supports JPEG, PNG and SVG images natively, all images supported by GD (GD, GD2, GD2PART, GIF, JPEG, PNG, BMP, XBM, XPM) and all images supported via ImagMagick (http:
  • 1D and 2D barcodes: CODE 39, ANSI MH10.8M-1983, USD-3, 3 of 9, CODE 93, USS-93, Standard 2 of 5, Interleaved 2 of 5, CODE 128 A/B/C, 2 and 5 Digits UPC-Based Extention, EAN 8, EAN 13, UPC-A, UPC-E, MSI, POSTNET, PLANET, RMS4CC (Royal Mail 4-state Customer Code), CBC (Customer Bar Code), KIX (Klant index – Customer index), Intelligent Mail Barcode, Onecode, USPS-B-3200, CODABAR, CODE 11, PHARMACODE, PHARMACODE TWO-TRACKS, QR-Code, PDF417;
  • Grayscale, RGB, CMYK, Spot Colors and Transparencies;
  • automatic page header and footer management;
  • document encryption up to 256 bit and digital signature certifications;
  • transactions to UNDO commands;
  • PDF annotations, including links, text and file attachments;
  • text rendering modes (fill, stroke and clipping);
  • multiple columns mode;
  • no-write page regions;
  • bookmarks and table of content;
  • text hyphenation;
  • text stretching and spacing (tracking/kerning);
  • automatic page break, line break and text alignments including justification;
  • automatic page numbering and page groups;
  • move and delete pages;
  • page compression (requires php-zlib extension);
  • XOBject templates;
Dynamically Creating TCPDF files in websites using TCPDF

Dynamically Creating TCPDF files in websites using TCPDF

There are 64 examples and there is no way I can explain the source code of each and every example from the official website, but the code is heavily commented enriched with detailed documentation and an active support forum at Sourceforge will really help you out to customize the code for your own needs.
So go ahead, take a look at the live demo, Download Source code and take a look at the documentation.

Click to Download Source Code of creating dynamic PDF files in website


Click to view Live Demo of creating dynamic PDF files in website

Live Demo

Click here to documentation of creating dynamic PDF files in website


Click here to go to Support Forum for dynamically creating PDF files in website

Support Forum

The live demo is hosted on our website and has been presented in a friendly layout which would easily let you understand how the code works.
If you need any support regarding this tutorial, then please leave your comment below and we will definitely respond to your question with a suitable solution.

TCPDF PHP class can be used to create almost any type of PDF file for all your purposes, but sometimes it is slight tricky to customize the script for our needs, if you ever run against any obstacles then please let us know and we will definitely help you.

Next week we will back with another unique and interesting tutorial in the meanwhile stay updated with all the tutorials at Geo Web Station by :

If you have any problems using the downloaded files, then leave a comment below.

Want more improvisations on this script ?, or want to request a new tutorial, then please Contact me right-away.

I promise to respond to everyone who contacts asking for support or new tutorials.

VN:F [1.9.22_1171]
Rating: 3.3/5 (4 votes cast)

, , , , , , , , , , , , , , , , , , ,