The name is too long ArgumentException

497 views Asked by At

When using iTextSharp.text.pdf.PdfStamper.AcroFields.SetField I get an ArgumentException on pdf form fields that appear after a certain point in the document. It says:

The name 'Helveia01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678' is too long (156 characters).

This is the internal name given to the form field by the pdf editor. The internal names seem to get longer and longer as you add more form fields (using Foxit). Its user-friendly name is just a short string (LiabilitiesTotal - below). If you look at the pdf in notepad, you can see the string above:

<>/DA(/Helveia0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567 0 Tf 0 0 0 rg)/AP<>/T(LiabilitiesTotal)>>

I have no control over this internal name. Any ideas why it has a limit when referenced by iTextSharp.text.pdf.PdfStamper.AcroFields.SetField? The PDF document is valid and I can fill it in manually, just not using PdfStamper

As an experiment I created a blank pdf using FoxitPhantomPDF 6.0.5.0618 and added 30 form fields keeping their default names. The result: the final form field is given an object name of Helveia0123456789012345678901234567, the first is called Helvei. From notepad++:

PDF examined in notepad++

Search "DA(/Helvei" (30 hits in 1 file)
C:\Users\sean.fackrell\Desktop\NewFoxit.pdf (30 hits) Line 36: <>/DA(/Helvei 0 Tf 0 0 0 rg)/AP<>>> Line 50: <>/DA(/Helveia 0 Tf 0 0 0 rg)/AP<>>> Line 64: <>/DA(/Helveia0 0 Tf 0 0 0 rg)/AP<>>> Line 78: <>/DA(/Helveia01 0 Tf 0 0 0 rg)/AP<>>> Line 92: <>/DA(/Helveia012 0 Tf 0 0 0 rg)/AP<>>> Line 106: <>/DA(/Helveia0123 0 Tf 0 0 0 rg)/AP<>>> Line 120: <>/DA(/Helveia01234 0 Tf 0 0 0 rg)/AP<>>> Line 134: <>/DA(/Helveia012345 0 Tf 0 0 0 rg)/AP<>>> Line 148: <>/DA(/Helveia0123456 0 Tf 0 0 0 rg)/AP<>>> Line 162: <>/DA(/Helveia01234567 0 Tf 0 0 0 rg)/AP<>>> Line 176: <>/DA(/Helveia012345678 0 Tf 0 0 0 rg)/AP<>>> Line 190: <>/DA(/Helveia0123456789 0 Tf 0 0 0 rg)/AP<>>> Line 204: <>/DA(/Helveia01234567890 0 Tf 0 0 0 rg)/AP<>>> Line 218: <>/DA(/Helveia012345678901 0 Tf 0 0 0 rg)/AP<>>> Line 232: <>/DA(/Helveia0123456789012 0 Tf 0 0 0 rg)/AP<>>> Line 246: <>/DA(/Helveia01234567890123 0 Tf 0 0 0 rg)/AP<>>> Line 260: <>/DA(/Helveia012345678901234 0 Tf 0 0 0 rg)/AP<>>> Line 274: <>/DA(/Helveia0123456789012345 0 Tf 0 0 0 rg)/AP<>>> Line 288: <>/DA(/Helveia01234567890123456 0 Tf 0 0 0 rg)/AP<>>> Line 302: <>/DA(/Helveia012345678901234567 0 Tf 0 0 0 rg)/AP<>>> Line 316: <>/DA(/Helveia0123456789012345678 0 Tf 0 0 0 rg)/AP<>>> Line 330: <>/DA(/Helveia01234567890123456789 0 Tf 0 0 0 rg)/AP<>>> Line 368: <>/DA(/Helveia012345678901234567890 0 Tf 0 0 0 rg)/AP<>>> Line 382: <>/DA(/Helveia0123456789012345678901 0 Tf 0 0 0 rg)/AP<>>> Line 396: <>/DA(/Helveia01234567890123456789012 0 Tf 0 0 0 rg)/AP<>>> Line 410: <>/DA(/Helveia012345678901234567890123 0 Tf 0 0 0 rg)/AP<>>> Line 424: <>/DA(/Helveia0123456789012345678901234 0 Tf 0 0 0 rg)/AP<>>> Line 438: <>/DA(/Helveia01234567890123456789012345 0 Tf 0 0 0 rg)/AP<>>> Line 452: <>/DA(/Helveia012345678901234567890123456 0 Tf 0 0 0 rg)/AP<>>> Line 466: <>/DA(/Helveia0123456789012345678901234567 0 Tf 0 0 0 rg)/AP<>>>

1

There are 1 answers

0
Chris Marisic On

ISO-32000-1 defines the limit for field names in a PDF file to be at maximum 127 bytes.

Source see Annex C ยง 2 Architectural limits "Table C.1" pages 649 and 650.