[reportlab-users] Acroform text widget alignment

Robin Becker robin at reportlab.com
Fri Oct 9 07:15:20 EDT 2020


On 09/10/2020 10:20, Chris Else wrote:
> Hi Robin,
> 
> Sorry but I'm stuck again.  Using your code, I was unable to set the
> NeedAppearances.
> 
>>>> if __name__=='__main__':
> ...   from reportlab.pdfgen.canvas import Canvas
> ...   canv = Canvas('aaa.pdf')
> ...   tf = canv.acroForm.textfield()
> ...   canv.acroForm['NeedAppearances'] = 'true'
> ...   canv.save()
> ...
> Traceback (most recent call last):
>    File "<stdin>", line 5, in <module>
> TypeError: 'AcroForm' object does not support item assignment
> 
> Any ideas?
> 
my stupidity the AcroForm only becomes a pdfdictionary at final assembly time. I patched the acroform file

diff -r 45bd9edde3c8 src/reportlab/pdfbase/acroform.py
--- a/src/reportlab/pdfbase/acroform.py	Fri Oct 02 16:37:46 2020 +0100
+++ b/src/reportlab/pdfbase/acroform.py	Fri Oct 09 12:08:37 2020 +0100
@@ -158,6 +158,7 @@
          self._refMap = {}
          self._pdfdocenc = {}
          self.sigFlags = None
+        self.extras = {}

      @property
      def canv(self):
@@ -179,6 +180,7 @@
              F = [self.fontRef(f) for f in FK]
              d['DA'] = PDFString('/%s 0 Tf 0 g' % FK[0])
              d['DR'] = PDFFromString('<< /Encoding\n<<\n/RLAFencoding\n%s\n>>\n%s\n>>' % (self.encRefStr,'\n'.join(F)))
+        d.update(self.extras)
          r = PDFDictionary(d).format(doc)
          return r

and then you can use

canv.acroForm.extras['NeedAppearances'] = 'true'

and the extras get rolled into the final dictionary.

I'll add this into the next micro release.

> Thank you
> 
> Chris Else
..........

-- 
Robin Becker


More information about the reportlab-users mailing list