Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
El siguiente fragmento de código también funciona con la biblioteca Aspose.PDF.Drawing.
Para obtener valores de todos los campos en un documento PDF, necesita navegar a través de todos los campos del formulario y luego obtener el valor usando la propiedad Value. Obtenga cada campo de la colección Form, en el tipo de campo base llamado Field y acceda a su propiedad Value.
Los siguientes fragmentos de código C# muestran cómo obtener los valores de todos los campos de un documento PDF.
// 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);
}
}
}
La propiedad Value del campo del formulario le permite obtener el valor de un campo particular. Para obtener el valor, obtenga el campo del formulario de la colección Form del objeto Document. Este ejemplo en C# selecciona un TextBoxField y recupera su valor usando la propiedad Value.
// 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);
}
}
}
Para obtener la URL del botón de envío, use las siguientes líneas de código.
// 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);
}
}
}
A veces, puede saber dónde en un documento se encuentra un campo de formulario, pero no tener su nombre. Por ejemplo, si todo lo que tiene es un esquema de un formulario impreso. Con Aspose.PDF for .NET, esto no es un problema. Puede averiguar qué campos están en una región dada de un archivo PDF. Para obtener campos de formulario de una región específica de un archivo PDF:
El siguiente fragmento de código C# muestra cómo obtener campos de formulario en una región rectangular específica de un archivo PDF.
// 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.