eForm Placeholder Example

ABCpdf .net

 
  

This example shows how to use eForm fields as placeholders for the insertion of text. In this example we simply replace each of the fields in a form with the name of that field.

 

  
Src 

First we create an ABCpdf Doc object and read in our template form.

[C#]
Doc theDoc = new Doc();
theDoc.Read(Server.MapPath("../mypics/form.pdf"));
theDoc.Font = theDoc.AddFont("Helvetica-Bold");
theDoc.FontSize = 16;
theDoc.Rect.Pin = (int)XRect.Corner.TopLeft;

[Visual Basic]
Dim theDoc As Doc = New Doc()
theDoc.Read(Server.MapPath("../mypics/form.pdf"))
theDoc.Font = theDoc.AddFont("Helvetica-Bold")
theDoc.FontSize = 16
theDoc.Rect.Pin = XRect.Corner.TopLeft

 

  

Add
 

We iterate through each of the fields. For each field we focus on the field. We then color the rectangle light gray and draw the name of the field in dark red.

[C#]
string[] theNames = theDoc.Form.GetFieldNames();
foreach (string theName in theNames) {
  Field theField = theDoc.Form[theName];
  theField.Focus();
  theDoc.Color.String = "240 240 255";
  theDoc.FillRect();
  theDoc.Rect.Height = 16;
  theDoc.Color.String = "220 0 0";
  theDoc.AddText(theField.Name);
  theDoc.Delete(theField.ID);
}

[Visual Basic]
Dim theNames As String() = theDoc.Form.GetFieldNames()
Dim theName As String
For Each theName In theNames
  Dim theField As Field = theDoc.Form(theName)
  theField.Focus()
  theDoc.Color.String = "240 240 255"
  theDoc.FillRect()
  theDoc.Rect.Height = 16
  theDoc.Color.String = "220 0 0"
  theDoc.AddText(theField.Name)
  theDoc.Delete(theField.ID)
Next

 

  

Save
 

Finally we save.

[C#]
theDoc.Save(Server.MapPath("eform.pdf"));

[Visual Basic]
theDoc.Save(Server.MapPath("eform.pdf"))

 

  

Results
 

Given the following document.


form.pdf

This is the kind of output you might expect.


eform.pdf