Toggling checkbox programmatically when filling a form

Skip Navigation LinksHome  /  Support  /  Forums  /  DynamicPDF CoreSuite for .NET (v10)  /  Re: Toggling checkbox programmatically when filling a form

DynamicPDF CoreSuite for .NET (v10) Forum

I've got an existing project using Dynamic PDF Merger that is able fill PDFs with known information from a CRM datasource. Up until now it's been all text fields, but now I need to start setting the value for check-boxes. My understanding is that this is done by setting the value on the form field to the export value of that field. Now  ideally I'd like to pull the export value from the PDF programmatically as I don't always know what that is. But Value is exposed on ceTe.DynamicPDF.Forms.FormField class, and ExportValue is on ceTe.DynamicPDF.Merger.Forms.PdfFormField.

Given that at the point in my code where I'm filling  in the PDF I have an instance of my PDF as ceTe.DynamicPDF.Merger.MergeDocument, is there an easy way to get the ExportValue of a field? It seems bizarre that the separation between the classes/namespaces is that that a ceTe.DynamicPDF.Merger.MergeDocument uses ceTe.DynamicPDF.Forms.FormFieldList (which is enumerable) and can expose a Value property but not ExportValue on a field. Yet ceTe.DynamicPDF.Merger.PdfDocument uses ceTe.DynamicPDF.Merger.Forms.PdfFormFieldList (which is NOT enumerable, that alone complicates things for me) but does expose ExportValue for its fields.

Is there a way to avoid hard coding the setting of a FormField's Value?
Posted by a ceTe Software moderator
Hello,

You can dynamically get the export values from checkboxes using a PdfFormField object. You will need to load the PDF into a PdfDocument object then retrieve the export value and set it to the form field. Below is a code sample:

            PdfDocument pdf = new PdfDocument(@"C:\temp\MyAcroForm.pdf");
            MergeDocument document = new MergeDocument(pdf);
            for (int i = 0; i < pdf.Form.Fields.Count; i++)
            {
                PdfFormField field = pdf.Form.Fields[i];
                string strExpVal=field.ExportValue;
                document.Form.Fields[i].Value = strExpVal;

            }
            document.Draw(@"C:\temp\MyForm.pdf");

Thanks,
ceTe Software Support Team
Is there a way to get an instance of a PdfDocument when all I have is MergeDocument instance? In this case, I only have a MergeDocument as a parameter to my method, I don't have access to the file system/stream to load/access the PdfDocument again by this point.
Posted by a ceTe Software moderator
Hello,

In order to retrieve the export values from existing form fields, you will need to load the PDF into a PdfDocument object. DynamicPDF Merger does not support getting a PdfDocument instance from a MergeDocument object, but you can use a PdfDocument object in the constructor of a MergeDocument.

Thanks,
ceTe Software Support Team

All times are US Eastern Standard time. The time now is 12:18 PM.