logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Post a reply
From:
Message:

Maximum number of characters in each post is: 32767
Bold Italic Underline   Highlight Quote Choose Language for Syntax Highlighting Insert Image Insert an existing Attachment or upload a new File... Create Link   Unordered List Ordered List   Left Justify Center Justify Right Justify   Outdent Indent   More BBCode Tags
Font Color Font Size
Security Image:
Enter The Letters From The Security Image:
  Preview Post Cancel

Last 10 Posts (In reverse order)
Alex Posted: Wednesday, April 27, 2022 9:28:25 PM(UTC)
 
Thanks Paul, this is a great peace of code and really helpful!

One more thing I wanted to ask about the drop down button on the right hand side of the field. Do we need to display our own button when the input field gets focus for example, or we can reuse some stock standard button available in Patagames SDK?

Best regards,
Alex.
Paul Rayman Posted: Wednesday, April 27, 2022 9:07:15 PM(UTC)
 
Hello,

You can intercept the click on the input field, show your own calendar and then set the value programmatically. Here is an illustration

Code:

public class MyPdfViewer : PdfViewer
{
    protected override void OnMouseDown(MouseEventArgs e)
    {
        if (e.Button == MouseButtons.Left)
        {
            if (Document != null)
            {
                var loc = e.Location;
                int idx = PointInPage(loc);
                if (idx >= 0)
                {
                    var pagePoint = ClientToPage(idx, loc);
                    int zOrder;
                    var ctrl = Document.Pages[idx].GetControlAtPoint((float)pagePoint.X, (float)pagePoint.Y, out zOrder);
                    if (ctrl != null && ctrl.Field.FieldType == Patagames.Pdf.Enums.FormFieldTypes.FPDF_FORMFIELD_TEXTFIELD)
                    {
                        if (FieldIsDateFormatted(Document, ctrl.Field))
                        {
                            MessageBox.Show("Show modaal calendar instead this");


                            //In fact, you should execute the below code after exiting the modal calendar dialog. And this is just an illustration.
                            Document.FormFill.ForceToKillFocus();
                            ctrl.Field.Value = "your own value";
                            Invalidate();
                        }
                    }
                }
            }
        }
        base.OnMouseDown(e);
    }

    private bool FieldIsDateFormatted(PdfDocument doc, PdfField field)
    {
        if (!field.Dictionary.ContainsKey("AA") || !field.Dictionary["AA"].Is<PdfTypeDictionary>())
            return false;

        var additionalAction = field.Dictionary["AA"].As<PdfTypeDictionary>();
        if (additionalAction.ContainsKey("F") && additionalAction["F"].Is<PdfTypeDictionary>())
        {
            var beforeDisplayAction = additionalAction["F"].As<PdfTypeDictionary>();
            var js = PdfAction.FromHandle(doc, beforeDisplayAction.Handle) as PdfJavaScriptAction;
            if ((js.JavaScript ?? "").Contains("AFDate_Format"))
                return true;
        }
        if (additionalAction.ContainsKey("K") && additionalAction["K"].Is<PdfTypeDictionary>())
        {
            var onTypeAction = additionalAction["K"].As<PdfTypeDictionary>();
            var js = PdfAction.FromHandle(doc, onTypeAction.Handle) as PdfJavaScriptAction;
            if ((js.JavaScript ?? "").Contains("AFDate_Keystroke"))
                return true;
        }
        return false;
    }
}
Alex Posted: Friday, April 22, 2022 12:02:35 AM(UTC)
 
Hi,

Hope someone here could help with our issue.

We have a pdf document with a text field configured as date in custom format dd/mm/yyyy. When opened in Acrobat reader, it shows a drop down arrow which can pop up a small calendar window to choose a date from (see the image below).

calendar.png

When we open the same pdf in Patagames PDF viewer (4.66.2704), the arrow is missing, and date can only be entered manually.

no-calendar.png

Is there a way to achieve the same behaviour as in Acrobat reader ?

Thanks in advance.