I am having an issue consistently checking checkbox fields. Sometimes they work fine and other times they don't. Enclosed is a PDF form (New Account Application.pdf) that has a number of other fields, but I key in on a set of checkboxes to check them all and the end result is that most are checked, some are not and I cannot figure out why. Also enclosed is the resulting output PDF file (New Account Application_OUTPUT_BAD.pdf). On page 2, the Net Worth and Estimated Liquid Assets sections of the FINANCIAL INFORMATION areas are supposed to all be checked.
Below is some sample code - we are using .Net PDF version 7.6.0.0. Would appreciate any explanation of what I may be doing wrong in either the setup of the form fields in the PDF or in my code. If there is a bug in the Aspose.Net PDF library, would appreciate a fix for this.
Regards,
Rob Cyrier
Code below is a .Net Console App.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace AsposeCheckboxTest
{
class Program
{
static void Main(string[] args)
{
Aspose.Pdf.License license = new Aspose.Pdf.License();
license.SetLicense("Aspose.Total.lic");
Aspose.Pdf.Document doc = new Aspose.Pdf.Document(@"C:\Impact\Code\LocalCode\AsposeCheckboxTest\New Account Application.pdf");
Aspose.Pdf.Facades.Form fform = new Aspose.Pdf.Facades.Form(doc);
LoadField(doc, fform, "Networth_1");
LoadField(doc, fform, "Networth_2");
LoadField(doc, fform, "Networth_3");
LoadField(doc, fform, "Networth_4");
LoadField(doc, fform, "Networth_5");
LoadField(doc, fform, "Networth_6");
LoadField(doc, fform, "Networth_7");
LoadField(doc, fform, "Liquid_Assets_1");
LoadField(doc, fform, "Liquid_Assets_2");
LoadField(doc, fform, "Liquid_Assets_3");
LoadField(doc, fform, "Liquid_Assets_4");
LoadField(doc, fform, "Liquid_Assets_5");
LoadField(doc, fform, "Liquid_Assets_6");
LoadField(doc, fform, "Liquid_Assets_7");
LoadField(doc, fform, "Liquid_Assets_8");
doc.Save(@"C:\Impact\Code\LocalCode\AsposeCheckboxTest\New Account Application_OUTPUT_BAD.pdf");
}
private static void LoadField(Aspose.Pdf.Document doc, Aspose.Pdf.Facades.Form form, string formFieldName)
{
Aspose.Pdf.InteractiveFeatures.Forms.Field interactiveField;
try
{
interactiveField = (Aspose.Pdf.InteractiveFeatures.Forms.Field)doc.Form[formFieldName];
}
catch
{
return;
}
// set a text box
if (interactiveField != null)
{
if (form.GetFieldType(formFieldName) == Aspose.Pdf.Facades.FieldType.CheckBox)
{
#region check box
form.FillField(formFieldName, true);
#endregion
}
}
}
}
}