How to generate PDF file from external text files using PHP ?
In this article, we will learn how to generate PDF files from external text files 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.
- 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 needs as shown in the following examples.
Example: The following code generates a PDF file based on external text files, namely “cIntro.txt”, “cStandard.txt” and “cPrototype.txt”. Refer to the comments in the code for better understanding and customisation as per the application’s needs.
C is a procedural programming language. It was initially developed by Dennis Ritchie in the year 1972.
It was mainly developed as a system programming language to write an operating system.
The main features of the C language include low-level memory access, a simple set of keywords, and a clean style, these features make C language suitable for system programmings like an operating system or compiler development.
Many later languages have borrowed syntax/features directly or indirectly from the C language.
C++ is nearly a superset of C language (Few programs may compile in C, but not in C++).
The latest C standard is ISO/IEC 9899:2011, also known as C11 as the final draft was published in 2011. Before C11, there was C99. The C11 final draft is available here. See this for a complete history of C standards.
Can we know the behavior of all programs from C standard?
C standard leaves some behavior of many C constructs as undefined and some as unspecified to simplify the specification and allow some flexibility in implementation.
For example, in C the use of any automatic variable before it has been initialized yields undefined behavior and the order of evaluations of subexpressions is unspecified.
This specifically frees the compiler to do whatever is easiest or most efficient, should such a program be submitted.
Function prototype tells compiler about number of parameters function takes, data-types of parameters and return type of function.
By using this information, compiler cross checks function parameters and their data-type with function definition and function call.
If we ignore function prototype, program may compile with warning, and may work properly.
But some times, it will give strange output and it is very hard to find such programming mistakes.
Above program checks existence of file, provided from command line, if given file is exist, then the program prints “file exist”, otherwise it prints appropriate error message.
Let us provide a filename, which does not exist in file system, and check the output of program on x86_64 architecture.