Handling information from Javascript annotations

We’re currently using the Windows PDFNet SDK for a PDF viewer built around the PDFViewCtrl. Many of users PDFs have information embedded in annotations. These usually bounding box around a component in the PDF, which when clicked on in Adobe produce a popup with information. I was just wondering if its currently possible to replicate this behaviour with PDFNet, or if anyone had previously come up with a solution? In the PDF they’re usually stored something like this

`

<</A<</JS( var citem = app.popUpMenu\( "Some Information Here" \); )/S/JavaScript/Type/Action>>/Border[0 0 0[4 2]]/C[1.0 1.0 0.0]/F 64/Rect[2142 245 2149 252]/Subtype/Link/Type/Annot>>

`

As far as I’m aware there’s no support for running JavaScript like this, right? My first approach was try and extract the text out of the annotation, and create a custom control to display it. I’ve overridden OnMouseDown in our control (which inherits from PDFViewCtrl) to try and get the annotation on the mouse click.

protected override void OnMouseDown(MouseEventArgs e) { var annot = this.GetAnnotationAt(e.X, e.Y); if (annot != null) { //handle annotation here } }

When I click on the object in the PDFViewCtrl the bounding box is highlighted, however GetAnnotationAt(e.X, e.Y) always returns null? What am I missing? Apologies if this is rather straight forward, I’m new to PDFNet and PDF formatting in general.

Thanks for your help.

Alex

Yes, PDFNet supports javascript actions on form fields. It is off by default.

PDFNet.EnableJavaScript(true);

https://www.pdftron.com/api/PDFTronSDK/dotnet/pdftron.PDFNet.html#pdftron_PDFNet_EnableJavaScript_System_Boolean_

Currently the engine supports the “app.alert” function, to trigger a dialog popup, but not “app.popUpMenu”.

Do you create the PDF files? Could you change the function to app.alert?

What effect does not having this popupmenu have on your customers/users?

Hi Ryan,

Thanks for the reply, I’m still fairly new to PDFNet and the PDF file structure in general. Unfortunately we don’t create the pdf files ourselves, so i can’t use the app.alert function. The files are created by customers using a range of packages, which all seem store text for popup annotations differently . The feature isn’t a requirement, I was just asked to see if it was possible while I was updating to the latest version of PDFNet and thought it was worth asking.

My first approach didn’t work, however the action was still getting executed so I could override the OnAction() method. Then I could get the text from the relevant actions (and then could create a control of my own). But I ran into another issue where some of the documents had the information stored like

`
/Type /Action /S /JavaScript /JS ( var symbol = [3, 76]; var prop = [5,[32,186],[237,1231],[53,78]]; _b._c(symbol,prop,’’,[]); )

`

where the call to _b._c call would search a table for the correct text and produce the PopUpMenu, I have no idea how to handle that. So i think for now we’ll shift displaying popups to Not Yet.