We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Setting the Export Value for the checkbox

Hello,

I am trying to set the Export Value of a checkbox (present in the Options tab of Properties window of field - check attached image).

I was able to set “Truck 1” as export value for the radio button using RadioButtonOptionField class. Is there any property on the CheckboxField class to set its Export Value to custom value instead of default “Yes”?

Here is my test code:

public void SetCheckBox()
{
var content = TestResources.GraphPaper;
<span style="color:blue;">using</span> (<span style="color:#2b91af;">MemoryStream</span> inStream = <span style="color:blue;">new</span> <span style="color:#2b91af;">MemoryStream</span>(content), 
        outStream = <span style="color:blue;">new</span> <span style="color:#2b91af;">MemoryStream</span>())
{
    <span style="color:blue;">using</span> (<span style="color:blue;">var</span> pdfDoc = <span style="color:blue;">new</span> Aspose.Pdf.<span style="color:#2b91af;">Document</span>(inStream))
    {
        <span style="color:blue;">var</span> random = <span style="color:#2b91af;">DateTime</span>.UtcNow.Ticks;
        <span style="color:blue;">var</span> pageNumber = 1;

        <span style="color:blue;">var</span> checkboxField = <span style="color:blue;">new</span> Aspose.Pdf.InteractiveFeatures.Forms.<span style="color:#2b91af;">CheckboxField</span>(pdfDoc.Pages[pageNumber],
            <span style="color:blue;">new</span> Aspose.Pdf.<span style="color:#2b91af;">Rectangle</span>(100, 600, 120, 620)) { PartialName = <span style="color:#a31515;">"PartialName "</span> + random };

        checkboxField.Border = <span style="color:blue;">new</span> <span style="color:#2b91af;">Border</span>(checkboxField) {Width = 1};
        checkboxField.Characteristics.Border = <span style="color:#2b91af;">Color</span>.Black;

        pdfDoc.Form.Add(checkboxField, 1);


        <span style="color:green;">//Add radio button</span>
        <span style="color:blue;">var</span> radio = <span style="color:blue;">new</span> Aspose.Pdf.InteractiveFeatures.Forms.<span style="color:#2b91af;">RadioButtonField</span>(pdfDoc.Pages[1])
        {
            PartialName = <span style="color:#a31515;">"PartialName radio "</span> + random
        };

        pdfDoc.Form.Add(radio, pageNumber);
        <span style="color:blue;">var</span> optionField = <span style="color:blue;">new</span> Aspose.Pdf.InteractiveFeatures.Forms.<span style="color:#2b91af;">RadioButtonOptionField</span>
        {
            OptionName = <span style="color:#a31515;">"Truck 1"</span>,
            Rect = <span style="color:blue;">new</span> Aspose.Pdf.<span style="color:#2b91af;">Rectangle</span>(100, 500, 120, 520)
        };
        radio.Add(optionField);
        optionField.Border = <span style="color:blue;">new</span> <span style="color:#2b91af;">Border</span>(optionField) {Width = 1};
        optionField.Characteristics.Border = <span style="color:#2b91af;">Color</span>.Black;

        pdfDoc.Save(outStream);

        <span style="color:#2b91af;">File</span>.WriteAllBytes(<span style="color:blue;">string</span>.Format(<span style="color:#a31515;">@"C:\Temp\checkbox_test_</span><span style="color:mediumseagreen;">{0}</span><span style="color:#a31515;">.pdf"</span>, random),
            outStream.ToArray());
    }
}

}

Thank you for your help,
Uday

Hi Uday,


Thanks for your inquriy. I am afraid currently Aspose does not support to set custom export value for checkbox, so I have logged an enhancement ticket PDFNEWNET-40625 in our issue tracking system for further investigation and resolution. We will keep you updated about the issue resolution progress.

We are sorry for the inconvenience caused.

Best Regards,