PDF Form having 200+ fields take a long time to filling up

Hi,


In our application, we handle PDF editable forms. We store the PDF form fields values in a database and while loading the form in our application we fill the form fields with the stored values.

We use Aspose.PDF for loading the PDFs with stored values. Below is a code piece that fills the PDF form fields with stored values.

PdfContentEditor contentEditor = new PdfContentEditor();
contentEditor.BindPdf(memoryStream_Of_PDFFormTemplate);

contentEditor.ReplaceTextStrategy.IsRegularExpressionUsed = true;
contentEditor.ReplaceTextStrategy.ReplaceScope = ReplaceTextStrategy.Scope.REPLACE_ALL;

// PDFDataValue is collection of PDF form fields and values.
// And below loop replaces text on the form template.
foreach (formData in PDFDataValue)
contentEditor.ReplaceText(formData.Name, formData.Value);

//save output PDF file
contentEditor.Save(memoryStream_Of_ToBeLoadPDF);
contentEditor.Close();

var pdfFormDoc = new Aspose.Pdf.Document(replaceFinal);

// Below loop is to fill the form fields.
foreach (var field in pdfFormDoc.Form)
{
var pdfField = ((PdfForms.Field)field);
var fieldName = pdfField.FullName;

if (field is PdfForms.ButtonField) { } // Not doing anything with PushButtons.
else if (field is PdfForms.TextBoxField || field is PdfForms.RichTextBoxField)
{
foreach (var data in PDFDataValue.Where(e => e.Name == fieldName))
{
txtField.Value = data.Value;
break;
}
}
else if (field is PdfForms.RadioButtonField)
{
foreach (var data in PDFDataValue.Where(e => e.Name == fieldName))
{
var rd = pdfField as PdfForms.RadioButtonField;
foreach (PdfForms.Option o in rd.Options)
if (o.Name == data.Value)
o.Selected = true;
break;
}
}
else if (field is PdfForms.ListBoxField)
{
foreach (var data in PDFDataValue.Where(e => e.Name == fieldName))
{
var lst = pdfField as PdfForms.ListBoxField;
List idList = new List();
foreach (PdfForms.Option o in lst.Options)
if (data.Value.Contains(o.Value))
idList.Add(o.Index);
lst.SelectedItems = idList.ToArray();
break;
}
}
else
{
foreach (var data in PDFDataValue.Where(e => e.Name == fieldName))
{
((PdfForms.Field)pdfFormDoc.Form[fieldName]).Value = data.Value;
break;
}
}
}

pdfFormDoc.Save(outputFinal);
replaceFinal.Close();

One of our PDF form has around 250 fields in it. While processing this form, the foreach loop to fill PDF template fields in above piece of code consumes more than 100 seconds (about 2 minutes).

Can you please suggest a better and faster approach to achieve this?

Currently we use Aspose.PDF 7.2, and I have tried out with the latest 9.3.0 version also, it also takes same amount of time.

Due to our organizaiton policies, I cannot provide the PDF form we are processing, but you can create a PDF form with 250 or more fields on it and test with that one.

Thanking you.

Thanks for your inquiry. It is quite difficult to suggest you anything about your issue without replicating at our end. We will suggest you can create some sample PDF at your end and share for investigation.

Moreover, you may try to use other options for your scenairo i.e. XML, FDF and XFDF data export and import. You may export data as any of the options and can import back later when required to populate data back into PDF form. Please check following documentation link for the purpose. Hopefully it will help you to accomplish the task.

  1. Export Data to XML from a PDF File
  2. Import Data from FDF into a PDF File
  3. Export Data to FDF from a PDF File
  4. Import Data from XFDF into a PDF File
  5. Export Data to XFDF from a PDF File

Please feel free to contact us for any further assistance.

Best Regards,

Hi,


Please try to replicate the issue at your end, with the code snippet provided in our earlier post, with the attached PDF.

Hi there,


Thanks for sharing the source document. I am afraid I am unable to replicate the issue due to missing references. We will appreciate it if you please share a console application with sample data for investigation.

We are sorry for the inconvenience caused.

Best Regards,
As requested, we are providing a sample application to process the PDF Form.

We have used Aspose.PDF version 9.3.0.

You need to apply the reference to Aspose.PDF in the Sample project.

We have also attached a result screenshot that shows total duration in minutes and seconds. As we reported earlier, it takes more than 100 seconds.

Please note:
1. This duration is during local run in a windows application.

2. The sample has only a loop that replaces the text in the Form. In real scenario, there will be some more code before and after the process but that does not effect negatively.

3. If this sample takes more than 100 seconds in Windows appliction (local run), then over the web this code would take double (perhaps more than double) time to execute i.e. more than 3 minutes. This is really annoying to end users.

4. There may be 5 to 10 seconds difference during your execution and that might be because of system configuration.
Kindly consider this as a CRITICAL issue.

Hi there,

Thanks for your inquiry. While testing the scenario with your shared document, we have managed to notice the performance issue with the latest version of Aspose.Pdf for .NET 9.7.0. We have logged a ticket PDFNEWNET-37645 in our issue tracking system for further investigation and resolution. We will notify you as soon as it is resolved.

We are sorry for the inconvenience caused.

Best Regards,