Quantcast
Channel: Aspose.Pdf Product Family
Viewing all articles
Browse latest Browse all 3131

PDF Fields

$
0
0
Hi,

I am creating a pdf from scratch and adding fields using Aspose.Pdf.Generator and Aspose.Pdf.Generator.FormField. The data in the fields will be entered in by the enduser. My problem is that I can not access the fields' values after data is entered into the pdf.  Below is my test code for creating the pdf and fields:
Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf(); 
Aspose.Pdf.Generator.Section sec1 = pdf1.Sections.Add();
Aspose.Pdf.Generator.Table table1 = new Aspose.Pdf.Generator.Table();
table1.ColumnWidths = "120 120 120";
sec1.Paragraphs.Add(table1);


Aspose.Pdf.Generator.Row row1 = table1.Rows.Add();

Aspose.Pdf.Generator.Cell cell1 = row1.Cells.Add("Name");
cell1.Padding.Left = 30;
cell1.Paragraphs[0].ID = "cell1";


Aspose.Pdf.Generator.Cell cell2 = row1.Cells.Add("City");
cell2.Padding.Left = 30;
cell2.Paragraphs[0].ID = "cell2";

Aspose.Pdf.Generator.Cell cell3 = row1.Cells.Add("State");
cell3.Padding.Left = 30;
cell3.Paragraphs[0].ID = "cell3";

Aspose.Pdf.Generator.FormField field = new Aspose.Pdf.Generator.FormField();
field.FormFieldType = Aspose.Pdf.Generator.FormFieldType.Text;
field.IsBordered = true;
field.TextFontName = "Tahoma";
field.TextFontSize = 8;
field.PositioningType = Aspose.Pdf.Generator.PositioningType.ParagraphRelative;
field.FieldName = "Name";
field.FormWidth = 80;
field.FormHeight = 15;
field.ReferenceParagraphID = "cell1";
field.Left = -20;
field.Top = 15;

Aspose.Pdf.Generator.FormField field2 = new Aspose.Pdf.Generator.FormField();
field2.FormFieldType = Aspose.Pdf.Generator.FormFieldType.Text;
field2.IsBordered = true;
field2.TextFontName = "Tahoma";
field2.TextFontSize = 8;
field2.PositioningType = Aspose.Pdf.Generator.PositioningType.ParagraphRelative;
field2.FieldName = "City";
field2.FormWidth = 80;
field2.FormHeight = 15;
field2.ReferenceParagraphID = "cell2";
field2.Left = -20;
field2.Top = 15;


Aspose.Pdf.Generator.FormField field3 = new Aspose.Pdf.Generator.FormField();
field3.FormFieldType = Aspose.Pdf.Generator.FormFieldType.Text;
field3.PositioningType = Aspose.Pdf.Generator.PositioningType.ParagraphRelative;
field3.IsBordered = true;
field3.TextFontName = "Tahoma";
field3.TextFontSize = 8;
field3.FieldName = "State";
field3.FormWidth = 80;
field3.FormHeight = 15;
field3.ReferenceParagraphID = "cell3";
field3.Left = -20;
field3.Top = 15;

sec1.Paragraphs.Add(field);
sec1.Paragraphs.Add(field2);
sec1.Paragraphs.Add(field3);
 pdf1.Save(fileName);

The code I used to try to access the data is below:
Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document("fileName");

foreach (Aspose.Pdf.Generator.FormField formField in pdfDocument.Form)
{
    System.Console.WriteLine("Field Name : {0} ", formField.FieldName);
    System.Console.WriteLine("Value : {0} ", formField.FieldValue);
}


Viewing all articles
Browse latest Browse all 3131

Trending Articles