2

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<>>>

sfax
  • 51
  • 3
  • Well, I'm meeting two project managers from Foxit tomorrow. I'll tell them about the problem. It *is* a problem as ISO-32000-1 explicitly says that names longer than 127 characters are forbidden. See ISO-32000-1 Annex C (normative): Implementation limits. name; 127; Maximum length of a name, in bytes. – Bruno Lowagie Aug 16 '13 at 02:15
  • By the way: /Helveia... is not the name of a field. It's the name of a font, so maybe you're allegation that Foxit is doing this, is wrong. I'd really like to see that file as there must be other places in the PDF where that font is defined. How was it originally created? – Bruno Lowagie Aug 16 '13 at 02:16
  • Thanks for your reply. I did suspect it was creating duplicate fonts but if you look at the properties of the pdf, it all looks normal. The PDF was created from a Word doc supplied by a client and form fields were added and named subsequently. I don't have Foxit on this laptop but I will confirm at work later whether it's repeatable in a new pdf. I'm pretty sure I created a new PDF with Foxit, added 10 form fields and saw the sequence of Helveia0123, Helveia01234, Helveia01235, Helveia01236 etc in a new document. I raised this with Foxit yesterday but I've had no response yet – sfax Aug 16 '13 at 06:36
  • Have added detail on what happens with a brand new blank PDF – sfax Aug 16 '13 at 07:41
  • Wow, this isn't supposed to happen. I'll pass this on to somebody at Foxit in Fremont. – Bruno Lowagie Aug 16 '13 at 12:43
  • Thanks Bruno. Appreciate your help – sfax Aug 16 '13 at 13:41
  • I received an answer from Foxit. They confirm that it's a bug in PhantomPDF 6.0 and that the bug will be fixed in 6.1 (to be released in a month). – Bruno Lowagie Aug 20 '13 at 05:58

1 Answers1

1

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.

Chris Marisic
  • 30,638
  • 21
  • 158
  • 255