I'm trying to add a TextBoxField to a pdf using this instruction:
doc = PdfDocument()
page = doc.Pages.Add() # add an empty page
page.Canvas.DrawString("TextBox:", font, brush1, PointF(10.0, baseY))
tbxBounds = RectangleF(baseX, baseY, 350.0, 15.0)
textBox = PdfTextBoxField(page, "name")
textBox.Bounds = tbxBounds
textBox.Font = font
doc.Form.Fields.Add(textBox)
and it works fine but if i try to add the same TextBoxField to a page of an existing pdf i get the excpetion "AttributeError: 'NoneType' object has no attribute 'Fields'", below the code i'm using:
infile = "/path/inputfile.pdf"
doc = PdfDocument()
doc.LoadFromFile(inputFile)
page = doc.Pages[0]
page.Canvas.DrawString("TextBox:", font, brush1, PointF(10.0, baseY))
tbxBounds = RectangleF(baseX, baseY, 350.0, 15.0)
textBox = PdfTextBoxField(page, "name")
textBox.Bounds = tbxBounds
textBox.Font = font
doc.Form.Fields.Add(textBox)
What's wrong?
thank you