Skip to main content

How to Convert Text File to PDF using Python

In this article i will show you How to Convert Text File to PDF using Python. FPDF is a Python Module 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.

To install the fpdf module type the belwo command in the terminal.

pip install fpdf

Then use the code below to change text file to pdf file

from fpdf import FPDF

#save FPDF() class into a variable pdf
pdf = FPDF()

#add a page
pdf.add_page()

#set style and size of the font you want
pdf.set_forn("Arial", size=15)

#open the text file in read mode
f = open("techcvr.txt", "r")

#insert the text in pdf
for x in f:
    pdf.cell(200, 10, txt = x, ln = 1, align = 'C')

#save the pdf with name .pdf
pdf.output("techcvr.pdf")

Enjoy : )

The post How to Convert Text File to PDF using Python appeared first on Tech CVR.



from Tech CVR https://www.techcvr.net/convert-text-file-to-pdf-using-python/

Comments

Popular posts from this blog

How to send WhatsApp message to any number without saving from Kodular App

Hello guys, to day i will show you a small guide to make an application where you can send whatsapp message to any registered whatsapp number without saving it. It is a very simple and easy to use method. Component you need is a button and a custom chrome tabs. below are the blocks image to make this type of app.

Tower Jumper – Free Android Game Source Code Download

Tower Jumper is a free to play Android Game where you have to reach the end of a tower avoiding the obstacles. Download Source Code For Free. This is a clone of a popular android game in which you move a jumping ball and try to reach the end of a tower avoiding the obstacles. The levels are randomly generated. This is a free (GPL-3.0) open source copy of some popular games full of ads, but without them. Its made with godot engine and the source code is available to download below All resources and code were made by the developer from scratch and are not derivative work of anything existent, just the game is similar to other already existent. The Developer make no profit with this game as its free, open source, and ad-free. The game was made for learning purposes and does not violates any copyright. Features – Easy to learn one tap controls – Very risk rewarding experience – Hold as long as possible to get perfect – Destroy different shaped stacks – Beat the high score ...