I am trying to align a text horizontally and vertically inside a Frame using ReportLab.
The problem is that even defining explicitly the arguments hAlign='CENTER' and vAlign='BOTTOM' for the KeepInFrame function, this does not change the default left horizontal alignment and top vertical alignment top.
I am using the latest version of ReportLab (reportlab==3.6.9).
Here's a code example:
# Import packages
import re
from reportlab.lib.enums import TA_CENTER
from reportlab.lib.pagesizes import A4
from reportlab.lib.styles import ParagraphStyle
from reportlab.lib.units import cm
from reportlab.pdfgen.canvas import Canvas
from reportlab.platypus import Paragraph, Frame, KeepInFrame
# Create document
doc = Canvas(filename='test.pdf', pagesize=A4, bottomup=1, pdfVersion=(1,4))
# Text
text = ("""Here is a simple text that should be hAlign='CENTER' and vAlign='BOTTOM'""")
text = re.sub(r'\n', '<br/>', text)
text = Paragraph(text, ParagraphStyle(name='', fontName='Helvetica', fontSize=11, textColor='black', alignment=TA_CENTER), encoding='utf8')
text = KeepInFrame(
maxWidth=0,
maxHeight=0,
content=[text],
mode='shrink',
hAlign='CENTER',
vAlign='BOTTOM',
fakeWidth=False,
)
# Create ReportLab Frame object
frame = Frame(
x1=2.5*cm,
y1=20*cm,
width=9.0*cm,
height=1.5*cm,
showBoundary=1
)
frame.addFromList([text], doc)
# Save document
doc.save()
Does anyone know how to fix this issue? Thanks in advance.

