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

Notification

Icon
Error

New Topic Post Reply
Options
Go to last post Go to first unread
Alex  
#1 Posted : Friday, April 22, 2022 12:02:35 AM(UTC)
Quote
Alex

Rank: Newbie

Groups: Registered
Joined: 3/21/2021(UTC)
Posts: 7
Australia
Location: Sydney

Thanks: 2 times
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.

Edited by user Tuesday, April 26, 2022 6:49:16 PM(UTC)  | Reason: Not specified

Paul Rayman  
#2 Posted : Wednesday, April 27, 2022 9:07:15 PM(UTC)
Quote
Paul Rayman

Rank: Administration

Groups: Administrators
Joined: 1/5/2016(UTC)
Posts: 1,050

Thanks: 5 times
Was thanked: 123 time(s) in 120 post(s)
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;
    }
}
thanks 1 user thanked Paul Rayman for this useful post.
Alex on 4/27/2022(UTC)
Alex  
#3 Posted : Wednesday, April 27, 2022 9:28:25 PM(UTC)
Quote
Alex

Rank: Newbie

Groups: Registered
Joined: 3/21/2021(UTC)
Posts: 7
Australia
Location: Sydney

Thanks: 2 times
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.
Quick Reply Show Quick Reply
Users browsing this topic
New Topic Post Reply
Forum Jump  
You can post new topics in this forum.
You can reply to topics in this forum.
You can delete your posts in this forum.
You can edit your posts in this forum.
You cannot create polls in this forum.
You can vote in polls in this forum.