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 –
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- Send PDF File through Email using pdf-mail module
- Convert PDF File Text to Audio Speech using Python
- Extract text from PDF File using Python
- Python | Convert Image to Pdf using img2pdf module
- Convert PDF to Image using Python
- Python Convert Html to PDF
- Convert Docx to Pdf usinf docx2pdf Module in Python
- How to convert a PDF document to a preview image in PHP?
- Build an Application to extract URL and Metadata from a PDF using Python
- Create a GUI to convert CSV file into excel file using Python
- Python | Reading contents of PDF using OCR (Optical Character Recognition)
- Exporting PDF Data using Python
- Merge PDF stored in Remote server using Python
- PDF Redaction using Python
- Add Watermark to PDF using PyPDF4 in Python
- Encrypt and Decrypt PDF using PyPDF2
- Convert Text File to CSV using Python Pandas
- Working with PDF files in Python
- Python | Scipy stats.halfgennorm.pdf() method
- Python | Scipy stats.hypsecant.pdf() method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.