Listen and get 'e.annots.inserted' event in own plugin

PDF-XChange Editor SDK for Developers

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

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
KarlTH
User
Posts: 57
Joined: Mon Aug 01, 2005 2:33 pm
Location: Salzburg - AUSTRIA
Contact:

Listen and get 'e.annots.inserted' event in own plugin

Post by KarlTH »

Dear Tracker-Support,

I am currently developing an own PDF-XChange Editor-plugin for digital signatures from DocuSign (PDFXEditControl.Inst.AddPlugin(myDocuSignPlugin) and need for it to listen and get an annot. I
made this work, if embedd the PDFXEditControl control with this code:

Code: Select all

 private int _idEventAnnotInserted;

    private void frmMain_Load(object sender, EventArgs e)
    {
        PDFXEditControl.VisibleCmdPanes = PXV_VisibleCmdPanes.PXV_VisibleCmdPanes_All;
        PDFXEditControl.OpenDocFromPath(@"C:\Temp\Vorlage_0383_03.pdf");

        // Get event and save event-id for listening
        _idEventAnnotInserted = PDFXEditControl.Inst.Str2ID("e.annots.inserted");
        PDFXEditControl.EnableEventListening2(_idEventAnnotInserted, true);
    }
    
    private void PDFXEditControl_OnEvent(object sender, _IPXV_ControlEvents_OnEventEvent e)
{
    if (e.nEventID == _idEventAnnotInserted)
    {
        // Listen for new added annot with event-id
        PDFXEdit.IPXV_AnnotsEvent annotsEvent = (IPXV_AnnotsEvent)e.pEvent;
        if (!annotsEvent == null)
        {
            // Get annot from event
            IPXC_Annotation annot = annotsEvent.Items(annotsEvent.Items.Count - 1);
            Debug.WriteLine(annot.Rect.left);
            Debug.WriteLine(annot.Rect.top);

            Debug.WriteLine("New annot with name '" + annot.Name + "' inserted!");
        }
    }
}

But I can't make the same work in my plugin and it drives me crazy. :oops:
I tried this but without success:

Code: Select all


public void Setup(PXV_Inst pInstance)
{
    IUIX_Inst uixInstance = pInstance.GetExtension("UIX");
   // Create custom event for listening
    uixInstance.CurrentThreadCtx.RegisterEventMonitor(new CustomEventMonitor(pInstance));
}

public class CustomEventMonitor : PDFXEdit.IUIX_EventMonitor
{
    public void OnEventMonitor(IUIX_Obj pTarget, IUIX_Event pEvent)
    {
        Debug.WriteLine(_uixInstance.ID2Str(pTarget.ID));
       // Get mouse click event instead of AnnotEvent
        if (pEvent.Code == System.Convert.ToUInt32(UIX_EventCodes.e_MouseCaptureLost))
        {
            IPXV_PagesLayoutManager activePageLayout = _pxvInstance.ActiveDocView.PagesView.Layout;
            PDFXEdit.IPXC_Page pdfPage = _pxvInstance.ActiveDoc.CoreDoc.Pages(activePageLayout.CurrentPage);
            uint nAnnotCount = pdfPage.GetAnnotsCount();

            if (nAnnotCount != 0)
            {
                for (uint i = 0; i <= nAnnotCount - 1; i++)
                {
                    PDFXEdit.IPXC_Annotation annot = pdfPage.GetAnnot(i);
                    PXC_Rect myRect = annot.Rect;
                }
            }
        }
    }
}
My main problem ist that I don't know how to get the annotsEvent in a custom EventMonitor of a plugin :shock: and therefore I used the mouse click event in my plugin:

Code: Select all

        if (pEvent.Code == System.Convert.ToUInt32(UIX_EventCodes.e_MouseCaptureLost))        
To get the annotsEvent in custom EventMonitor doesn't work as expected and so I hope you can help me!
(Easiest would be that I can listen to OnEvent from the PDFXEditControl in my plugin but I am afraid this would work)


Best regards,
Karl
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Listen and get 'e.annots.inserted' event in own plugin

Post by Sasha - Tracker Dev Team »

Hello Karl,

What you need, is to create an IEventHandler derived class and implement all of the needed methods. The OnEvent method will catch all of the registered events.
In the FinalizeRegistering method of your plugin, you will have to create that IEventHandler derived class and do something this with the needed events:

Code: Select all

m_pListener = new AppEventListener(this);

	if (m_pListener != nullptr)
	{
		m_pListener->AddRef();
		CComPtr<PXV::IEventServer> es;
		m_pInst->get_EventServer(&es);
		es->RegisterNativeEventHandler(id_e_customizeCmdLayout, m_pListener, 0);
		es->RegisterNativeEventHandler(id_e_beforeShowContextMenu, m_pListener, 0);
		es->RegisterNativeEventHandler(id_e_app_settingsChanged, m_pListener, 0);
		es->RegisterNativeEventHandler(id_e_docSelection_changed, m_pListener, 0);
	}
Then in the IEventHandler derived class, you should catch the events like this:

Code: Select all

STDMETHODIMP AppEventListener::OnEvent(LONG nEventID, PXV::IEvent* pEvent, IUnknown* pFrom)
{
	if (!pEvent || !pFrom)
		return 0;

	if (nEventID == id_e_customizeCmdLayout)
	{
	
	}
Note that if you have string IDs you will have to convert them to numeric IDs.


Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
KarlTH
User
Posts: 57
Joined: Mon Aug 01, 2005 2:33 pm
Location: Salzburg - AUSTRIA
Contact:

Re: Listen and get 'e.annots.inserted' event in own plugin

Post by KarlTH »

Hi Alex,

I wouldn't have found this on my own without you help! You are my hero! :)
I have tested it with AppEventListener and it works perfect! Great! :D

THANK YOU SO MUCH!

One question to AppEventLister parameter, just for understanding:

Code: Select all

m_pListener = new AppEventListener(this);
(this) as parameter in this code line represents the instance to PXV_Plugin or PXV_Inst?
AppEventListener works also without (this) as parameter. Just for my understanding!


THANK YOU

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

Re: Listen and get 'e.annots.inserted' event in own plugin

Post by Sasha - Tracker Dev Team »

Hello Karl,

In my case I gave it the IPXV_Plugin implementation so that the listener had access to all of the needed data on my side.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
KarlTH
User
Posts: 57
Joined: Mon Aug 01, 2005 2:33 pm
Location: Salzburg - AUSTRIA
Contact:

Re: Listen and get 'e.annots.inserted' event in own plugin

Post by KarlTH »

Hello Alex,

thank you! :)


Best regards,

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

Re: Listen and get 'e.annots.inserted' event in own plugin

Post by Sasha - Tracker Dev Team »

:)
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Post Reply