I am test-driving your product. I am going to have a simple form, mostly pre-defined text, with a few fields derived from the database.
I created a simple, one field .pdf in Acrobat Designer and have tried using that as a MergeDocument. When I try to assign a value to the one field, the field is not found.
Using your example, fw9AcroForm_03.pdf, as the merge document, I am able to assign values from my database to its fields.
How do I create a .pdf with fields that can be recognized in .Net?
Also, I noticed that in Acrobat Designer, the names of the fields in your fw9AcroForm_03.pdf usually have a "_" in them, for example, "fl_2". However, in the code-behind, those fields are referenced as "fl-2" with a regular "-" dash. Why is that?
Simple example
Re: Simple example
Support · Feb 10, 2006The likely reason that the form field is not being picked up is because the name that you are specifying is not the complete name of the actual form field. Acrobat Designer typically saves the names of the form fields in a hierarchical manner. A form field's name could be the concatenation of its parents name like "Parent2.Parent1.FormFieldName" instead of "FormFieldName" as might be expected.
The referencing of the form fields is actually case sensitive and "fl_2" would not match "fl-2". I just checked our examples and from everything I could see all the form fields in the PDFs and all the references used a dash and not an underscore. If you are seeing somewhere that this does not match can you let us know the exact location (which build, which language, which folder, which example, etc.) so that we can look into it and get it resolved if needed.
Thanks,
ceTe Software Support Team
Re: Simple example
Forum member · Feb 10, 2006Regarding the naming convention, when I open fw9AcroForm_03.pdf in Acrobat Designer 7.0, it labels the fields with an underscore instead of a dash.
What is the simplest way get this to work? Using your .pdf, this code works. Your f1-1 and f1-2 fields have my data in them. Also, if I set a Watch on document.Forms.Fields, it returns a value of {ceTe.DynamicPDF.Forms.FormFieldList}.
document.Form.Fields["f1-1"] returns {ceTe.DynamicPDF.Merger.Forms.MergeTextField}.
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack )
{
// Create a MergeOptions object to import the AcroForm
MergeOptions options = new MergeOptions( true );
// Create a document and set it's properties
MergeDocument document = new MergeDocument( MapPath("PDFs/fw9AcroForm_03.pdf"), options );
document.Creator = "MergePDFTest.aspx";
document.Author = "";
document.Title = "Test";
// Establises connection to the database
SqlConnection connection = GetOpenDBConn();
SqlDataReader data = GetContactListData( connection );
// Add content to the page
while( data.Read() )
{
document.Form.Fields["f1-1"].Value = data.GetString(14);
document.Form.Fields[ "f1-2" ].Value = data.GetString(20);
}
// Uncomment to make form read only
document.Form.IsReadOnly = true;
// Outputs the W-9 to the current web page
document.DrawToWeb( this, "TestTemplate1.pdf" );
Response.End();
}
}
HOWEVER, if I use my test.pdf, with one field in it, the fields collection is recognized but the single field is not. It returns this,
document.Form.Fields[ "f1-1" ] function 'document.Form.Fields.get_Item' evaluated and returned null
Finally, in trying to work through this, I have been saving my .pdf files in Acrobat Designer in different ways. When I save as a statid .pdf file, the file works with the MergeDocument function. If I save as a dynamic .pdf file, then the MergeDocument step produces a Index array out of bounds error.
Re: Simple example
Support · Feb 10, 2006This is still likely an issue with the name of the form field. If you would like to know the exact name of the form field on your PDF you could output the results of the line:
document.Form.Fields[0].FullName
This should return the full name of that form field.
Also I just wanted to make sure that you are specifying a MergeOptions( true ) in the MergeDocument constructor just like below. This is needed to be able to fill in the form fields also.
If you still have any question after trying this feel free to send over the document that you are using and we can take a look at it. You can send it to [^a|mailto:support@cete.com|support@cete.com^].
Thanks,
ceTe Software Support Team
Re: Simple example
Forum member · Feb 10, 2006MergeOptions is set to true as in my code posted previously. When I debug with your fw9AcroForm_03.pdf then document.Form.Fields has a Count=30. With my form, no matter how many fields I add, Count=1, and it isn't my field. I've sent an email with my .pdf attached. Thanks for your assistance. Your product is going to be a great help.
Re: Simple example
Forum member · May 9, 2007I am having a similar problem. I'm using Adobe Designer to create a PDF with form fields. No matter how many form fields I add, the FormFields collection is always 1. The name of the field is always F[0] which is not the name of any of the fields I've created. Step-by-step instructions would be helpful on creating a PDF with forms fields that can be accessed using your Merger product. Can you help?
Thanks,
Brian
Re: Simple example
Support · May 9, 2007Adobe Designer uses a hierarchical naming convention for the form fields that are defined from within that application. There is nothing wrong or incorrect about this and these form fields created in Designer can for sure, as is, be referenced from within Merger. You do need to make sure to specify the full name of the form field when referencing any form field from within our component (whether it is created with Designer or not).
So in your case, I guess the F[0] is the top level parent field for all the form fields on the document. And yes there is only one top level container field that is why it is returning one field. If you were to access that top field 'F[0]'s child fields you would see the rest of your form fields.
So to access all your form fields you will need to use the full name. The full name will be something like: 'F[0].ChildField[0].fieldname'. This is the name that you will need to reference in Merger.
We do have an example that you could use if you wanted to get a complete list of the exact names of the form fields in the document. Take a look at our Form Field Reader example that comes with our Evaluation edition. This example, by traversing all the levels of hierarchy in a documents form field, will return all the field full names.
Thanks,
ceTe Software Support Team
Re: Simple example
Forum member · May 9, 2007Thanks for the speedy response; this information was useful to solving my problem. I created a function that allows the control to be accessed by name only for similar cases. Here it is for anyone that wants it:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim MyDocument As MergeDocument = New MergeDocument(MapPath("~/ui/reports/templates/AcroForm.pdf"))
With MyDocument
.Creator = ""
.Author = ""
.Title = ""
End With
Dim PrePays As FormField = SetFormField("PrePays", MyDocument.Form.Fields)
PrePays.Value = "Hello World"
'Perform Other Steps
MyDocument.DrawToWeb("Hello World", True)
Response.End()
End Sub
Public Function SetFormField(ByVal sFieldName As String, ByVal FormFieldList As FormFieldList) As FormField
Dim MyFormField As FormField = Nothing
For Each CeTeFormField As FormField In FormFieldList
If CeTeFormField.Name.Replace("[0]", "") = sFieldName Then
MyFormField = CeTeFormField
Else
MyFormField = SetFormField(sFieldName, CeTeFormField.ChildFields)
End If
If MyFormField IsNot Nothing Then
Exit For
End If
Next CeTeFormField
Return MyFormField
End Function