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; // } //} } } }