1

I want to use pdfrw and ReportLab to:

  1. open an existing PDf and add a line of text to it based on x and y coordinates (via ReportLab - drawCentredString(x,y,string)

  2. insert the resulting pdf into my report.

So far, here's what I've tried as a modified version of code from here:

from pdfrw import PdfReader
from pdfrw.buildxobj import pagexobj
from pdfrw.toreportlab import makerl
from reportlab.pdfgen import canvas

folder='Documents/Assets/'
x = PdfReader(folder+'/'+'BACK_PAGE.pdf',decompress=False).pages
y = pagexobj(x)
c = canvas.Canvas(folder+'/'+'BACK_PAGE_out.pdf')
c.doForm(makerl(c, y))
c.showPage() 
c.save()

This is just to open the pdf and save it as a new one (baby steps). The problem is, I get this error:

AttributeError: 'list' object has no attribute 'inheritable'

Thanks in advance for any insight.

P.S. I know there is a similar question here, but it is old and I can't get the solutions to work.

Community
  • 1
  • 1
Dance Party
  • 3,459
  • 10
  • 42
  • 67

1 Answers1

1

The error occurred because:

y = pagexobj(x)

needed to be:

y = pagexobj(x[0]) 

instead (so as not to be a list, as the error implies).

Dance Party
  • 3,459
  • 10
  • 42
  • 67