Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Fri May 24, 2024 12:58 pm

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

gcarream2sc
 
Posts: 1
Joined: Thu May 23, 2024 6:50 am

Mon May 27, 2024 6:07 am

Hi,

Thanks for inquiry and sorry to reply late for weekend.
I tested with Spire.PDF for Python 10.5.2 and did not have the problem you described. If you are not testing with 10.5.2, please update to 10.5.2 to test as the new version will contain more fixes. If you still have problems, please provide your system environment (e.g. Windows 10) and send your test file to 'support@e-iceblue.com' and we will investigate further. Thanks in advance for your assistance!

Sincerely,
Doris
E-iceblue support team
User avatar

Doris.Liu
 
Posts: 409
Joined: Mon Nov 07, 2022 8:10 am

Return to Spire.PDF