PDFs are one of the most important and widely used digital media. PDF stands for Portable Document Format. It uses
FPDF is a Python class that allows generating PDF files with Python code. It is free to use and it does not require any API keys. FPDF stands for Free PDF. It means that any kind of modification can be done in PDF files.
The main features of this class are:
- Easy to use
- It allows page format and margin
- It allows to manage page header and footer
- Python 2.5 to 3.7 support
- Unicode (UTF-8) TrueType font subset embedding
- Barcode I2of5 and code39, QR code coming soon …
- PNG, GIF and JPG support (including transparency and alpha channel)
- Templates with a visual designer & basic html2pdf
- Exceptions support, other minor fixes, improvements and PEP8 code cleanups
To install the fpdf module type the belwo command in the terminal.
pip install fpdf
- Import the class FPDF from module fpdf
- Add a page
- Set the font
- Insert a cell and provide the text
- Save the pdf with “.pdf” extencsion
Converting text file to PDF
Now if we want to make the above program more advance what we can do is that from a given text file extract the data using file handling and then insert it into the pdf file. The approach is all same as above, one thing you have to do is extract the data from a text file using file handling.
Note: Refer this article to know more about file handling in Python.
Example: Let’s suppose the text file looks like this –
- Convert Text file to JSON in Python
- Python: Convert Speech to text and text to Speech
- Extract text from PDF File using Python
- Saving Text, JSON, and CSV to a File in Python
- Python | Scramble words from a text file
- Extract numbers from a text file and add them using Python
- Convert Text to Speech in Python
- Convert emoji into text in Python
- Python program to extract Email-id from URL text file
- Python | Finding 'n' Character Words in a Text File
- Count number of lines in a text file in Python
- Python | Convert image to text and then to speech
- Python | Create an empty text file with current date as its name
- Python program to Reverse a single line of a text file
- Python | Count occurrences of each word in given text file (Using dictionary)
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.