Execute link annotation actions from code  SOLVED

PDF-XChange Editor SDK for Developers

Moderators: TrackerSupp-Daniel, Tracker Support, Vasyl-Tracker Dev Team, Sean - Tracker, Paul - Tracker Supp, Chris - Tracker Supp, Tracker Supp-Stefan, Ivan - Tracker Software

Forum rules
DO NOT post your license/serial key, or your activation code - these forums, and all posts within, are public and we will be forced to immediately deactivate your license.

When experiencing some errors, use the IAUX_Inst::FormatHRESULT method to see their description and include it in your post along with the error code.
Post Reply
zarkogajic
User
Posts: 648
Joined: Thu Sep 05, 2019 12:35 pm

Execute link annotation actions from code

Post by zarkogajic » Thu Apr 02, 2020 1:33 pm

Hi Support,

How do I mimic link annotation click - to execute actions it has?

p.s.
Similar to, if I'm not wrong, what "cmd.bookmarksView.goto" does for a selected bookmark.



zarkogajic
User
Posts: 648
Joined: Thu Sep 05, 2019 12:35 pm

Re: Execute link annotation actions from code

Post by zarkogajic » Sat Apr 04, 2020 12:33 pm

Hi Support,

I've tried IPXV_ActionHandler::Perform but it either fails with an error "parameter incorrect" or no error but nothing happens (e.document.beforeRunAction does not fire).

Since an annot can have multiple actions I would need to know what parameters (in Perform) to use for each - if the above is the way to go.


User avatar
Sasha - Tracker Dev Team
User
Posts: 4885
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Execute link annotation actions from code

Post by Sasha - Tracker Dev Team » Mon Apr 06, 2020 1:38 pm

Hello zarkogajic,

Hmm, I don't see any problem with the Perform method:

Code: Select all

private void addLinkAnnotToolStripMenuItem_Click(object sender, EventArgs e)
{
	PDFXEdit.IPXS_Inst pSInt = (PDFXEdit.IPXS_Inst)pdfCtl.Inst.GetExtension("PXS");
	//Getting Free Text annotation atom for the InsertNewAnnot method
	uint nLink = pSInt.StrToAtom("Link");
	PDFXEdit.IPXC_Page pPage = pdfCtl.Doc.CoreDoc.Pages[0];
	PDFXEdit.PXC_Rect rc;
	rc.left = 0;
	rc.right = 150;
	rc.top = 150;
	rc.bottom = 0;
	PDFXEdit.IPXC_Annotation pAnnot = pPage.InsertNewAnnot(nLink, ref rc, 0);
	if (pAnnot == null)
		return;
	//Filling the annotation with needed text
	PDFXEdit.IPXC_AnnotData_Link FTData = (PDFXEdit.IPXC_AnnotData_Link)pAnnot.Data;
	FTData.Contents = "https://www.google.com";
	PDFXEdit.IPXC_ActionsList AL = pdfCtl.Doc.CoreDoc.CreateActionsList();
	PDFXEdit.IPXC_Action uri = AL.AddURI("https://www.google.com");
	pAnnot.set_Actions(PDFXEdit.PXC_TriggerType.Trigger_Up, AL);
	PDFXEdit.PXC_AnnotBorder border = new PDFXEdit.PXC_AnnotBorder();
	border.nStyle = PDFXEdit.PXC_AnnotBorderStyle.ABS_Underline;
	border.nWidth = 2;
	FTData.set_Border(ref border);
	PDFXEdit.IColor color = auxInst.CreateColor(PDFXEdit.ColorType.ColorType_RGB);
	color.SetRGB(0.0f, 0.0f, 1.0f);
	FTData.Color = color;
	pAnnot.Data = FTData;
	//Executing the operation so that the annotation will be updated from structure
	int nID = pdfCtl.Inst.Str2ID("op.annots.addNew", false);
	PDFXEdit.IOperation pOp = pdfCtl.Inst.CreateOp(nID);
	PDFXEdit.ICabNode input = pOp.Params.Root["Input"];
	input.Add().v = pAnnot;
	pOp.Do();

	IPXV_ActionHandler handler = pdfCtl.Inst.GetHandlerForAction(uri.Type);
	handler.Perform(pdfCtl.Doc, uri, null, 0, 0);
}
Cheers,
Alex
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

zarkogajic
User
Posts: 648
Joined: Thu Sep 05, 2019 12:35 pm

Re: Execute link annotation actions from code

Post by zarkogajic » Mon Apr 06, 2020 3:54 pm

Thanks Alex,

I'll give it another try ...

Anyhow, nothing like "cmd.bookmarksView.goto" for link annots ?

-žarko

User avatar
Sasha - Tracker Dev Team
User
Posts: 4885
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Execute link annotation actions from code

Post by Sasha - Tracker Dev Team » Tue Apr 07, 2020 6:46 am

Hello zarkogajic,

The IPXV_ActionHandler::Perform method will do just that.

Cheers,
Alex
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

zarkogajic
User
Posts: 648
Joined: Thu Sep 05, 2019 12:35 pm

Re: Execute link annotation actions from code

Post by zarkogajic » Tue Apr 07, 2020 1:55 pm

Hi Alex,

Thanks. I was setting the nClass (PAEC_Link) and nSubclass (PAESC_MouseUp) parameters in my test-try.

Once I've cleared those out it started to work.

However, the e.document.beforeRunAction does *not* get fired - and I need it to happen so I can custom handle what will happen...

-žarko

zarkogajic
User
Posts: 648
Joined: Thu Sep 05, 2019 12:35 pm

Re: Execute link annotation actions from code

Post by zarkogajic » Mon Apr 13, 2020 10:04 am

Hi Alex,

I've "fixed" this by calling the same code I use in "e.document.beforeRunAction" - sending it the ipxc_action to for those I want to custom handle and calling Perform for the rest. So consider solved.

But do please confirm that Perform not raising the event is by design?

Ž

User avatar
Sasha - Tracker Dev Team
User
Posts: 4885
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Execute link annotation actions from code

Post by Sasha - Tracker Dev Team » Mon Apr 13, 2020 12:32 pm

Hello zarkogajic,

It does not raise it internally. Also, do not forget about the https://sdkhelp.tracker-software.com/vi ... rRunAction event that you should fire afterwards.

Cheers,
Alex
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

zarkogajic
User
Posts: 648
Joined: Thu Sep 05, 2019 12:35 pm

Re: Execute link annotation actions from code

Post by zarkogajic » Mon Apr 13, 2020 3:13 pm

Hi Alex,

How to do it (and why)?

ž

User avatar
Sasha - Tracker Dev Team
User
Posts: 4885
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Execute link annotation actions from code

Post by Sasha - Tracker Dev Team » Mon Apr 13, 2020 7:09 pm

Hello zarkogajic,

Well in case that you want to emulate the fully correct behavior, you would have to construct and fire your before/after events. That is if you need that.

Cheers,
Alex
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

zarkogajic
User
Posts: 648
Joined: Thu Sep 05, 2019 12:35 pm

Re: Execute link annotation actions from code

Post by zarkogajic » Mon Apr 13, 2020 7:25 pm

Yes, I thought of doing that, I'm just not sure how to fire the needed events. So, a code sample, please.

ž

User avatar
Sasha - Tracker Dev Team
User
Posts: 4885
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Execute link annotation actions from code

Post by Sasha - Tracker Dev Team » Tue Apr 14, 2020 7:03 am

Hello zarkogajic,

Here's a code sample that I had on this matter:

Code: Select all

pdfCtl.Doc.CoreDoc.Props.set_ViewPrefFlag(PDFXEdit.PXC_DocumentViewFlags.DocViewFlag_DisplayDocTitle, true);
pdfCtl.Doc.CoreDoc.SrcInfo.CustDispTitle = "Custom Title";
var evtID = pdfCtl.Inst.Str2ID("e.document.propsChanged", false);
IntPtr unkPtr = System.Runtime.InteropServices.Marshal.GetIUnknownForObject(pdfCtl.Doc);
PDFXEdit.IEvent evt = pdfCtl.Doc.EventServer.CreateNewEvent(evtID, (uint)unkPtr, (uint)PDFXEdit.PXC_DocumentViewFlags.DocViewFlag_DisplayDocTitle);
pdfCtl.Doc.EventServer.FireEvent(evt, pdfCtl.Doc);
Cheers,
Alex
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

zarkogajic
User
Posts: 648
Joined: Thu Sep 05, 2019 12:35 pm

Re: Execute link annotation actions from code

Post by zarkogajic » Tue Apr 14, 2020 8:35 am

Hi Alex,

Yes, but I need to fire an IPXV_DocActionEvent - and I'm not sure how to create one of such kind.

Should I create a class implementing IPXV_DocActionEvent?

Then:

1. CreateNewEvent -> returns iEvent
2. Use it in my custom IPXV_DocActionEvent implementation ( + setting Action, TriggerClass, TriggerSubclass and ActionData)
3. FireEvent (my IPXV_DocActionEvent event)

If so, what should be the last parameter value in CreateNewEvent ?


User avatar
Sasha - Tracker Dev Team
User
Posts: 4885
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Execute link annotation actions from code

Post by Sasha - Tracker Dev Team » Tue Apr 14, 2020 9:14 am

Hello zarkogajic,

The CreateEvent will return an already implemented interface that you only need to set with your needed data.
BTW...
Just found the IPXV_Inst::PerformActions method that will do the events firing and all of the needed work.

Cheers,
Alex
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

zarkogajic
User
Posts: 648
Joined: Thu Sep 05, 2019 12:35 pm

Re: Execute link annotation actions from code  SOLVED

Post by zarkogajic » Tue Apr 14, 2020 9:50 am

Hi Alex,

Yes, PerformActions is the way to go, thanks!


User avatar
Sasha - Tracker Dev Team
User
Posts: 4885
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Execute link annotation actions from code

Post by Sasha - Tracker Dev Team » Tue Apr 14, 2020 11:26 am

:)
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

Post Reply