1
I have a dict()
with string data extracted from a arquivo.txt
.
dic = {}
dic[valor[0]] = valor[1]
print(dic)
>>> dic = {'Almir': 44, 'Ana': 36 ....}
I would like to save organized in PDF as follows:
nome : 8585
nome : 83838
1
I have a dict()
with string data extracted from a arquivo.txt
.
dic = {}
dic[valor[0]] = valor[1]
print(dic)
>>> dic = {'Almir': 44, 'Ana': 36 ....}
I would like to save organized in PDF as follows:
nome : 8585
nome : 83838
3
Install the reportlab:
pip install reportlab
Creating the PDF and saving:
from reportlab.pdfgen import canvas
c = canvas.Canvas("arquivo.pdf")
#(x, y, string)
c.drawString(0,0,str(dic))
c.save()
If you want to look at the documentation: https://www.reportlab.com/docs/reportlab-userguide.pdf
1
As suggested by @cryptotux, use the library reportlab.
To generate the PDF through a dictionary, where each word will be on a line, do:
import os
from reportlab.pdfgen import canvas
from reportlab.lib.units import inch
# Aqui vem o código de criação do dicionário `dic`
c = canvas.Canvas("arquivo.pdf")
# Move a origem do cursor para a parte superior esquerda
c.translate(inch,inch)
# Inicia um objeto texto limitando a área para que linhas
# muito grandes, não ultrapassem a margem.
textobject = c.beginText(0, 650)
textobject.setFont("Helvetica-Oblique", 14)
# Percorrendo o dicionário definido anteriormente
for key, value in dic.items():
textobject.textLine(key + ' : ' + value)
c.drawText(textobject)
c.showPage()
c.save()
os.system('arquivo.pdf')
Browser other questions tagged python pdf pdf-generation dictionary
You are not signed in. Login or sign up in order to post.
Dude, it worked, but when I try to put with more than one line the data is saved all in one line
– R.Aslan
could help me?
– R.Aslan
Is it really necessary to use PDF? It’s not a practical format to manipulate via code.
– cryptotux