Acroform text widget alignment

Chris Else <[email protected]> Thu, 8 Oct 2020 11:01:16 +0100
Newsgroups gmane.comp.python.reportlab.user
Message-ID <CAB0HUwSzH+0q+9nqJa4P6YYogc8vp4RQU5tkSWcnOp7edWpVUQ@mail.gmail.com>
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