views:

58

answers:

1

So I have the following VB.NET code that creates a form field in a PDF using SyncFusion's Essential PDF module:

Dim pdfField As New Pdf.Interactive.PdfTextBoxField(pdfDoc.Pages(iPage), "txt1")
pdfField.Location = New PointF(50, 50)
pdfField.Size = New SizeF(100, 10)
pdfDoc.Form.Fields.Add(pdfField)

This works great except for one thing. When I open up the PDF in Acrobat and look at the field name I notice that it says "txt1-0". Now I can't figure out where the "-0" is coming from and how to get rid of it.

This may be a SyncFusion issue, in which case I hope I get an answer from them soon (I've asked this on their forum). But I thought it might also be a fundamental detail about PDF's and naming that I don't know about.

+2  A: 

Ah ha, I just found out what was causing this.

Previously I was using both the PdfLoadedDocument and PdfDocument classes. I was loading the PdfLoadedDocument into the PdfDocument via ImportPages and apparently this process will add the "-0" suffix to the field names.

I found that in my case I can get rid of the PdfDocument object and just use PdfLoadedDocument and that fixed it.

UPDATE:

Just to expand on this, I've found that it's actually the PdfDocument.Form.FieldAutoNaming property that controls this. It's default value is true. And when it's set to true it'll automatically add suffixes as needed to prevent duplicate field names. But if you set it to false then it won't add the suffix "-0" anymore -- instead you might get errors in your code.

Steve Wortham