Checkbox is incorrectly used as "Check Mark" instead of "Cross Mark"

Posted by: fletchsod.developer on 23 July 2020, 8:42 am EST

  • Posted 23 July 2020, 8:42 am EST

    We noticed the issue with the way GrapeCity handle the PDF document. One of our support team use Adobe Acrobat Reader DC to program the checkbox field by giving it a name, checkmark style, etc. In this case, it is programmed as cross mark style. When loading this PDF into GrapeCity documents, I end up as cross mark style instead. Anyone know why is that? I have attached 2 PDFs, one is correct & other is wrong.


    var pdfFieldNames = pdfDocument.AcroForm.Fields.Select(v => v.Name).ToList();

    // Previously, document.AcroForm.Fields was being used to retrieve PDF fields. However, this caused issues
    // with multiple fields having the same name (e.g. "P Req Signature"), in that all but one of those fields
    // would be ignored. Looking, instead, at each page's annotations seems to be the solution.
    foreach (var page in pdfDocument.AcroForm.Doc.Pages)
    {
    foreach (var annotation in page.Annotations)
    {
    if (annotation.GetType() == typeof(WidgetAnnotation))
    {
    var widgetAnnotation = annotation as WidgetAnnotation;
    var fieldName = widgetAnnotation.Field.Name;
    TextField txtField;
    CheckBoxField chkField;
    RadioButtonField rdbField;
    bool isString = false; // Do we really need this?

    widgetAnnotation.Border.Style = BorderStyle.None;

    if (pdfFieldNames.Contains(fieldName))
    {
    var fieldResult = _formService.SendDpValuesToPdf(fieldName, formWriter, ref isString);
    if (fieldResult.Value != null)
    {
    if (isString == false)
    if (decimal.TryParse(fieldResult.Value, out decimal result))
    {
    fieldResult.Value = result.ToString("F");
    }

    if ((txtField = widgetAnnotation.Field as TextField) != null)
    {
    //if (fieldValue.StartsWith(_signaturePrefix) && fieldValue.EndsWith(_signatureSuffix))
    if (fieldResult.Value.StartsWith(@"\"))
    {
    // This is for DocuSign.
    // The text layout used to render input fields when flattening the document:
    var _inputTl = new gcText::TextLayout();
    _inputTl.ParagraphAlignment = gcText::ParagraphAlignment.Center;
    // The text format used for input fields:
    var _inputTf = new gcText::TextFormat();
    _inputTf.Font = StandardFonts.Courier;
    _inputTf.ForeColor = dotnetDrawing::Color.Transparent;
    _inputTf.FontSize = 4;
    _inputTf.FontBold = false;

    _inputTl.Clear();
    _inputTl.Append(fieldResult.Value, _inputTf);
    _inputTl.MaxHeight = widgetAnnotation.Rect.Height;
    _inputTl.PerformLayout(true);
    widgetAnnotation.Page.Graphics.DrawTextLayout(_inputTl, widgetAnnotation.Rect.Location);
    }
    else
    {
    //widgetAnnotation.Field.Value = fieldValue;
    txtField.Value = fieldResult.Value;
    txtField.RichText = false;
    }
    }
    else if ((chkField = widgetAnnotation.Field as CheckBoxField) != null)
    {
    // TODO - Change checkbox style from "check" mark to "cross" mark.
    // - https://www.grapecity.com/documents-api-pdf/docs/readme/version3.1.0.508.html
    // (Only version 3.1.0.508 & up support this).
    // (Added WidgetAnnotation.CheckStyle property. It specifies the style of check mark used if the WidgetAnnotation is linked to CheckBoxField or RadioButtonField).
    // - https://www.grapecity.com/documents-api-pdf/docs/online/GrapeCity.Documents.Pdf~GrapeCity.Documents.Pdf.Annotations.CheckStyle.html
    // -
    //chkField.???? = CheckStyle.Cross;

    chkField.Value = EvaluatePdfCheckboxField(fieldResult.Value);
    }
    else if ((rdbField = widgetAnnotation.Field as RadioButtonField) != null)
    {
    rdbField.Value = EvaluatePdfCheckboxField(fieldResult.Value);
    }
    }
    }
    //else
    //{
    // if ((txtField = widgetAnnotation.Field as TextField) != null)
    // {
    // txtField.Value = txtField.Value;
    // }
    //}
    }
    }
    }

    Example1.Wrong.pdf.zip
  • Replied 23 July 2020, 8:43 am EST

    I can't attached the 2nd file cuz it is 6.1 MB long & this forum only accept 5 MB max.
  • Replied 23 July 2020, 10:14 pm EST

    Hi Scott,

    In order to investigate the issue, we need the second PDF file and the stripped-down sample which shows the code that you are using to modify your document. It will help us to assist you accordingly.

    You can upload the files on the given link:
    https://www.dropbox.com/request/QLx6TzV8dAqu71fANnhu


    Regards,
    Prabhat Sharma.
  • Replied 24 July 2020, 3:38 pm EST

    Hello,

    Here is the correct link given below:
    https://www.dropbox.com/request/t8cReCO00wLyUYcbjxj4

    Regards,
    Prabhat Sharma.
  • Replied 26 July 2020, 11:41 pm EST

    Done! Uploaded both files on DropBox. Please let us know ASAP on scripts workaround to this issue that we can upload in our source code. Thanks.
  • Replied 27 July 2020, 4:14 pm EST

    Hello Scott,

    Thank you for the PDF files and we too can see some difference in the PDF files but it seems that both the files are handled differently.
    As we said earlier to further investigate this we need to know what operation you are performing on these PDFs and how. So can you please share a stripped-down sample which shows the difference so that we can replicate the same behavior at our end and assist you accordingly.

    Regards,
    Prabhat Sharma.
  • Replied 27 July 2020, 11:55 pm EST

    Here you go below. The incorrect PDF file, you can open it in Adobe Acrobat Reader DC (Professional version) & see all checkboxes have different properties settings.

    var page in pdfDocument.AcroForm.Doc.Pages
    var annotation in page.Annotations

    if (annotation.GetType() == typeof(WidgetAnnotation))
    {
    var widgetAnnotation = annotation as WidgetAnnotation;
    var fieldName = widgetAnnotation.Field.Name;
    CheckBoxField chkField;

    if ((chkField = widgetAnnotation.Field as CheckBoxField) != null)
    {
    chkField.Value = true;
    }
    }
  • Replied 29 July 2020, 10:11 pm EST

    Hi Scott,

    We have processed both the PDF files as per your given code and added the sample and the PDFs in the link given below:
    https://www.dropbox.com/s/a5xgip6fbb9vfw7/Demo%20%282%29.zip?dl=0

    Can you please let us know the difference that you are facing at your end with the help of the screenshots comparing your pdf and the pdf generated via GcPdf. It will help us to further investigate this issue.

    Regards,
    Prabhat Sharma.
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels