is there a way to trigger actions from code?

I am using the InterceptAnnotationHandling functionality to extract the Link annotation to handle GoTo_R links

When I open the document that is being linked to can I manually create a Goto link and execute it?

_pdfDoc = new PDFDoc(FilePath);
Destination dest = Destination.CreateFitR( page, l, b, r, t);
var pageView = pdftron.PDF.Action.CreateGoto(dest);

_pdfView.SetDoc(_PdfDoc);

// Execute pageView action ???

Thanks

Jamie

Could you confirm which platform you are asking about. Is it UWP?

Can you also elaborate on exactly what API you are referring to with InterceptAnnotationHandling?

Hi Ryan,

We are using Xamarin so implementation will need to be on IOS, Android and UWP

InterceptAnnotationHandling is part of the PDFTron ToolManager

Flow is

Client Opens a PDF
Clicks Link
Intercept Link and process to determine which document they want
Open or download and open document

What I need to be able to do is if there is a destination set as part of the link in the original document, I need to got that part of the document.

Thanks

Sorry for the delay in a reply.

A link annotation can be created like this:

Action goto_page_3 = Action.createGoto(Destination.createFitH(doc.getPage(3), 0)); com.pdftron.pdf.annots.Link link = com.pdftron.pdf.annots.Link.create(doc.getSDFDoc(), new Rect(85, 458, 503, 502), goto_page_3); first_page.annotPushBack(link);

When interacting with the link:

Action a = link.getAction(); ActionParameter action_param = new ActionParameter(a); pdfViewCtrl.executeAction(actionParam);

If this is not what you are looking for, can you please elaborate in details exactly what you are trying to achieve so we can better assist.

Thanks Ryan, that is what I am looking for,

What is the way to do this in Xamarin for IOS

the PDFViewCtrl ExecuteAction or ExecuteActionWithActionParameter functions both use PT implemetations of Action or ActionParameter is there a way to convert from and Action or ActionParameter to the PT version of these or create these PTAction / PTActionParameters?

Thanks

Yes, you would want to use method:

TypeConvertHelper.ConvActionToNative(…)

and
TypeConvertHelper.ConvActionParameterToNative(…)

Please let us know how it works for you. Thanks.

Hi Ryan,

While it works on IOS I am getting an error on Android (pdfron.Android 6.9.0)

{Java.Lang.NullPointerException: Attempt to invoke virtual method ‘com.pdftron.sdf.Obj com.pdftron.pdf.Action.getSDFObj()’ on a null object reference
at Java.Interop.JniEnvironment+InstanceMethods.CallNonvirtualVoidMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniObjectReference type, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x00089] in <0ad2222fd7074badb5de547b1521aab0>:0
at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualVoidMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x0005d] in <0ad2222fd7074badb5de547b1521aab0>:0
at pdftronprivate.PDF.PDFViewCtrl.ExecuteAction (pdftronprivate.PDF.ActionParameter p0) [0x00031] in <30b392ec98784c849d0cf1c9b6544d46>:0
at pdftron.PDF.PDFViewCtrl.ExecuteAction (pdftron.PDF.ActionParameter actionParam) [0x00007] in <30b392ec98784c849d0cf1c9b6544d46>:0
at Field.Mobile.Droid.Renderers.PdfViewerRenderer.ExecuteAction (pdftron.PDF.Action action) [0x00009] in C:\Work\FieldMobileApp\App\Field.Mobile\Field.Mobile.Droid\Renderers\PdfViewerRenderer.cs:608
— End of managed Java.Lang.NullPointerException stack trace —
java.lang.NullPointerException: Attempt to invoke virtual method ‘com.pdftron.sdf.Obj com.pdftron.pdf.Action.getSDFObj()’ on a null object reference
at com.pdftron.pdf.PDFViewCtrl.executeAction(SourceFile:8111)
at mono.java.lang.RunnableImplementor.n_run(Native Method)
at mono.java.lang.RunnableImplementor.run(RunnableImplementor.java:30)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

using the following code

// INFO - (linkedDestination.PageNumber = 1)

ExecuteAction(pdftron.PDF.Action.CreateGoto(Destination.CreateFit(_pdfDoc.GetPage(linkedDestination.PageNumber))));

private void ExecuteAction(pdftron.PDF.Action action)
{
try
{
ActionParameter a_p = new ActionParameter(action);
_pdfView.ExecuteAction(a_p);
}
catch (Exception ex)
{
throw ex;
}
}

Any ideas?

Thanks

Jamie

H

This means the Action you passed in is not valid.

Can you please do:

if (action != null && action.IsValid())
{

}

Hi,

This made no difference the action is returning as valid,

Thanks.

Hi,

Would it be possible if you could share us the file you are testing with and a complete code snippet so we can reproduce it on our side?
Thank you!

Best Regards.