[reportlab-users] Acroform text widget alignment
Chris Else
ubuntu247 at gmail.com
Thu Oct 8 06:01:16 EDT 2020
Hi,
I'm trying to create a PDF containing an interactive form, where the
Textfield widgets have centered text.
I can achieve what I want by modifying the ReportLab generated PDF, but
it's not ideal and a bit brutal.
import fitz
import re
pdf = fitz.open("original.pdf")
for w in pdf[0].widgets():
# Not 100% sure this is the best way to add /Q 1
contents = re.sub("^ /", " /Q 1\n /", pdf.xrefObject(w.xref), 1,
re.MULTILINE)
pdf.updateObject(w.xref, contents)
pdf.need_appearances(True)
pdf.save("fixed.pdf")
In terms of PDF specification, I'm trying to add "/Q 1" to the widget's
/Annot dictionary.
In the ReportLab source code, src/reportlab/pdfbase/pdfform.py there is a
definition for TextFieldPattern.
Does anyone have any suggestions on how I may override this?
Or the possibility to add an alignment option to the textfield method?
Thank you.
Chris Else
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pairlist2.pair.net/pipermail/reportlab-users/attachments/20201008/4620a0c8/attachment.html>
More information about the reportlab-users
mailing list