How to create a table in PDF file from external text files using PHP ?
In this article, we will learn to create a table in a PDF file from an external text file with PHP by using FPDF. It is a free PHP class that contains many functions for creating and modifying PDFs. The FPDF class includes many features like page formats, page headers, footers, automatic page break, line break, image support, colors, links, and many more.
Approach: You need to download the FPDF class from the FPDF website and include it in your PHP script.
Instantiate and use the FPDF class according to your need as shown in the following examples.
Example: The following example generates a table in a PDF file from an external text file “employees.txt” having employee data. The file can be downloaded or previewed as needed. Refer to the comments in the code for better understanding and customization as per the application’s needs.
employees.txt: The following is the content for file “employees.txt” which is used in the above HTML file.
Aman;Varanasi;33;80750 Beena;Bombay;30;10100 Derek;Calcutta;43;52950 Fanny;Hubli;30;51000 Tom;Pondicherry;23;58000 Gleny;Bombay;32;82000 George;Atlanta;32;10500 Ishita;Dubai;34;36940 Iman;Rome;30;57560 Lily;Ranikhet;25;42400 Nihita;Agra;41;15600 Polima;Jaipur;45;99500 Seela;Madras;50;39300 Swati;Spain;41;88390 Janu;London;24;58860
Please Login to comment...