Rank: Newbie
Groups: Registered
Joined: 3/21/2021(UTC) Posts: 7  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).

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

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
|
|
|
|
Rank: Administration
Groups: Administrators
Joined: 1/5/2016(UTC) Posts: 1,027
Thanks: 5 times Was thanked: 122 time(s) in 119 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;
}
}
|
 1 user thanked Paul Rayman for this useful post.
|
|
|
Rank: Newbie
Groups: Registered
Joined: 3/21/2021(UTC) Posts: 7  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.
|
|
|
|
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.
Important Information:
The Patagames Software Support Forum uses cookies. By continuing to browse this site, you are agreeing to our use of cookies.
More Details
Close