How to find all instances of the input text box in pdf file using aspose

288 Views Asked by At

I have one pdf file and in that I have editable text boxes. It has around 20 textboxes.. Now I need to update values in that using some variables..

Like in textbox1 value sholuld come from Var1 etc..

I am using .Net-C# aspose PDF library..

So my concern is how can I access that textbox in my code, I have tried with TextFragmentAbsorber but not getting that.

Check below image you will see 3 textboxes so I want to fetch that and want to set some values in that.

enter image description here

TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber();
1

There are 1 best solutions below

0
silverfighter On

I would suggest looking at the documentation. A quick search found me this to access the form fields:

// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Forms();

// Open document
Document pdfDocument = new Document(dataDir + "GetValuesFromAllFields.pdf");

// Get values from all fields
foreach (Field formField in pdfDocument.Form)
{
    Console.WriteLine("Field Name : {0} ", formField.PartialName);
    Console.WriteLine("Value : {0} ", formField.Value);
}

Source where I found it: https://docs.aspose.com/pdf/net/extract-form/

this is from the example on how to populate form fields:

// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Forms();

// Open document
Document pdfDocument = new Document(dataDir + "FillFormField.pdf");

// Get a field
TextBoxField textBoxField = pdfDocument.Form["textbox1"] as TextBoxField;

// Modify field value
textBoxField.Value = "Value to be filled in the field";
dataDir = dataDir + "FillFormField_out.pdf";
// Save updated document
pdfDocument.Save(dataDir);

Source: https://docs.aspose.com/pdf/net/fill-form/