Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
The following code snippet also work with Aspose.PDF.Drawing library.
To get values from all the fields in a PDF document, you need to navigate through all the form fields and then get the value using the Value property. Get each field from the Form collection, in the base field type called Field and access its Value property.
The following C# code snippets show how to get the values of all the fields from a PDF document.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void GetValuesFromFields()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_Forms();
// Open PDF document
using (var document = new Aspose.Pdf.Document(dataDir + "GetValuesFromAllFields.pdf"))
{
// Get values from all fields
foreach (Aspose.Pdf.Forms.Field formField in document.Form)
{
Console.WriteLine("Field Name : {0} ", formField.PartialName);
Console.WriteLine("Value : {0} ", formField.Value);
}
}
}
The form field’s Value property allows you to get the value of a particular field. To get the value, get the form field from the Document object’s Form collection. This C# example selects a TextBoxField and retrieves its value using the Value property.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void GetValueFromField()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_Forms();
// Open PDF document
using (var document = new Aspose.Pdf.Document(dataDir + "GetValueFromField.pdf"))
{
// Get a field
if (document.Form["textbox1"] is Aspose.Pdf.Forms.TextBoxField textBoxField)
{
// Get field value
Console.WriteLine("PartialName : {0} ", textBoxField.PartialName);
Console.WriteLine("Value : {0} ", textBoxField.Value);
}
}
}
To get the submit button’s URL, use the following lines of code.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void GetSubmitFormActionUrl()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_Forms();
// Open PDF document
using (var document = new Aspose.Pdf.Document(dataDir + "GetValueFromField.pdf"))
{
// Get the SubmitFormAction from the form field
if (document.Form[1].OnActivated is Aspose.Pdf.Annotations.SubmitFormAction act)
{
// Output the URL of the SubmitFormAction
Console.WriteLine(act.Url.Name);
}
}
}
Sometimes, you might know where in a document a form field is, but not have it’s name. For example, if all you have to go from is a schematic of a printed form. With Aspose.PDF for .NET, this is not a problem. You can find out which fields are in a given region of a PDF file. To get form fields from a specific region of a PDF file:
The following C# code snippet shows how to get form fields in a specific rectangular region of a PDF file.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void GetFieldsFromRegion()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_Forms();
// Open PDF document
using (var document = new Aspose.Pdf.Document(dataDir + "GetFieldsFromRegion.pdf"))
{
// Create rectangle object to get fields in that area
var rectangle = new Aspose.Pdf.Rectangle(35, 30, 500, 500);
// Get the PDF form
var form = document.Form;
// Get fields in the rectangular area
var fields = form.GetFieldsInRect(rectangle);
// Display Field names and values
foreach (var field in fields)
{
// Display image placement properties for all placements
Console.Out.WriteLine("Field Name: " + field.FullName + "-" + "Field Value: " + field.Value);
}
}
}
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.