2
Good afternoon, I’m creating a program to generate certificates, but I’m having trouble centralizing the names, how could I do that? For every name is of a size.
I tried the center(), but it didn’t work. Follow the code:
from reportlab.pdfgen import canvas
from reportlab.lib.utils import ImageReader
from reportlab.lib.pagesizes import letter, landscape, A4
from reportlab.lib.units import mm, inch
# Caminho para a imagem de fundo
logo = ImageReader('Certificado.png')
# Tamanho da página
size_page = (1235*mm, 873*mm)
# Tamanho Fonte Nome
size_name = 140
# Nome local
name_x = 0
name_y = 1380
# Fonte
font = "Helvetica-Bold"
def GeneratePDF(lista):
try:
for indice, nome in enumerate(lista):
# Gerar certificado
pdf = canvas.Canvas('{}.pdf'.format(nome))
# Tamanho da página do certificado
pdf.setPageSize(size_page)
# Imagem de fundo
pdf.drawImage(logo, 0, 0)
pdf.setFont(font, size_name)
pdf.drawString(name_x, name_y, '{}'.format(nome))
pdf.save()
print('{}.pdf criado com sucesso!'.format(nome))
except:
print('Erro ao gerar pdf')
lista = ["Gabriel Nunes Delfino", "Teste"]
GeneratePDF(lista)
My last vote of the day.
– Augusto Vasques
our. I’ve been at s.o. for about 8 years and I don’t think I’ve ever used all the votes. : -) . Win which medal?
– jsbueno
You win this one: https://answall.com/help/badges/62/suffrage
– hkotsubo
I’m not lazy about voting on good content, I really vote.
– Augusto Vasques
the class needed to vote more - - is full of good answers around with "8 thousand views" and two votes.
– jsbueno
If I put 297 x 210mm my background is very out, I could not other way but so. I tried what you went through, it did not work. https://github.com/nunesdelfino/Certified
– Gabriel Delfino
Is there a better way to do that than I wish? I would recommend something?
– Gabriel Delfino
have to resize the image before adding it to the canvas with the
.drawImage
-the documentation is not very good, and you will need to experiment- try to pass the parameterswidth
andheight
when calling drawImage and see if it resizes the image.– jsbueno