Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
Form class provides the capability to deal with static AcroForm and you can get a particular field instance using the Form class’ GetFieldFacade(..) method. However, XFA fields cannot be accessed via the Form.GetFieldFacade(..) method. Instead, use Document.Form.XFA to get/set field values and manipulate XFA field template (set field properties).
The following code snippet also work with Aspose.PDF.Drawing library.
The following code snippet shows you how to fill fields in XFA form.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void FillXFAFields()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_Forms();
// Open PDF document
using (var document = new Aspose.Pdf.Document(dataDir + "FillXFAFields.pdf"))
{
// Get names of XFA form fields
var names = document.Form.XFA.FieldNames;
// Set field values
if (names.Length > 0)
{
document.Form.XFA[names[0]] = "Field 0";
}
if (names.Length > 1)
{
document.Form.XFA[names[1]] = "Field 1";
}
// Save PDF document
document.Save(dataDir + "FilledXfa_out.pdf");
}
}
Dynamic forms are based on an XML specification known as XFA, the “XML Forms Architecture”. The information about the form (as far as a PDF is concerned) is very vague – it specifies that fields exist, with properties, and JavaScript events, but does not specify any rendering.
Currently, PDF supports two different methods for integrating data and PDF forms:
We cannot extract or manipulate pages of XFA Forms, because the form content is generated at runtime (during XFA form viewing) within the application trying to display or render the XFA form. Aspose.PDF has a feature that allows developers to convert XFA forms to standard AcroForms.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void ConvertDynamicXFAToAcroForm()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_Forms();
// Load dynamic XFA form
using (var document = new Aspose.Pdf.Document(dataDir + "DynamicXFAToAcroForm.pdf"))
{
// Set the form fields type as standard AcroForm
document.Form.Type = Aspose.Pdf.Forms.FormType.Standard;
// Save PDF document
document.Save(dataDir + "StandardAcroForm_out.pdf");
}
}
To access field properties, first use Document.Form.XFA.Template to access the field template. The following code snippet shows the steps of getting X and Y coordinates of XFA a form field.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void GetXFAProperties()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_Forms();
// Open PDF document
using (var document = new Aspose.Pdf.Document(dataDir + "GetXFAProperties.pdf"))
{
// Get names of XFA form fields
var names = document.Form.XFA.FieldNames;
// Set field values
if (names.Length > 0)
{
document.Form.XFA[names[0]] = "Field 0";
}
if (names.Length > 1)
{
document.Form.XFA[names[1]] = "Field 1";
}
// Get field position
if (names.Length > 0)
{
Console.WriteLine(document.Form.XFA.GetFieldTemplate(names[0]).Attributes["x"].Value);
Console.WriteLine(document.Form.XFA.GetFieldTemplate(names[0]).Attributes["y"].Value);
}
// Save PDF document
document.Save(dataDir + "FilledXfa_out.pdf");
}
}
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.