Get annot item when changing annot state

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
lidds
User
Posts: 510
Joined: Sat May 16, 2009 1:55 pm

Get annot item when changing annot state

Post by lidds »

I am using the following code to change the annotation state

Code: Select all

Dim JS As New StringBuilder
        JS.AppendLine("//JS Code to search for an annotation and get status of it where StateInModel is Review")
        JS.AppendLine("//the JS output is passed to the SDK IString Res")
        JS.AppendLine("this.syncAnnotScan();")
        JS.AppendLine("var annots = this.getAnnots({")
        JS.AppendLine("nPage: 0,")
        JS.AppendLine("nSortBy: ANSB_Author,")
        JS.AppendLine("bReverse: true")
        JS.AppendLine("});")
        JS.AppendLine("")
        JS.AppendLine("var stateResults;")
        JS.AppendLine("var returnResults;")
        JS.AppendLine("returnResults = """";")
        JS.AppendLine("identity.name = """ & MISData.Instance.FirstName & """;")
        JS.AppendLine("for (var i = 0; i < annots.length; i++) {")
        If statusName = "None" Then
            JS.AppendLine("annots[i].transitionToState(""Review"",""None"");")
        ElseIf statusName = "Accepted" Then
            JS.AppendLine("annots[i].transitionToState(""Review"",""Accepted"");")
        ElseIf statusName = "Cancelled" Then
            JS.AppendLine("annots[i].transitionToState(""Review"",""Cancelled"");")
        ElseIf statusName = "Completed" Then
            JS.AppendLine("annots[i].transitionToState(""Review"",""Completed"");")
        ElseIf statusName = "Rejected" Then
            JS.AppendLine("annots[i].transitionToState(""Review"",""Rejected"");")
        End If

        JS.AppendLine("}")

        Dim res As PDFXEdit.IString = Me.docPreview.Inst.CreateString()
        Try
            Me.docPreview.Inst.ExecuteJS(Me.docPreview.Doc, JS.ToString, PDFXEdit.PXV_ActionTriggerClass.PAEC_External, PDFXEdit.PXV_ActionTriggerSubclass.PAESC_Exec, Nothing, res)
        Catch ex As Exception
            Console.WriteLine("Error changing annotation state: " & convertErr(ex))
        End Try
Is there anyway that I can get the annotation elements that I am changing the state of? e.g. if I have a rectangle and I run the above code, is there anyway I can get the rectangle annotation element as a IPXC_Annotation?

Thanks

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

Re: Get annot item when changing annot state

Post by Sasha - Tracker Dev Team »

Hello Simon,

Well the e.annots.changed event is being fired along with the annotations list as a parameter when you do transitionToState.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
lidds
User
Posts: 510
Joined: Sat May 16, 2009 1:55 pm

Re: Get annot item when changing annot state

Post by lidds »

Thanks Alex, got this working now.

Just out of interest the JS code that I posted obviously gets all annotation elements and set all annotation element status. How would I just set the selected annotations state?

Thanks

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

Re: Get annot item when changing annot state

Post by Sasha - Tracker Dev Team »

Hello Simon,

Get annotations from the current document's selection. Next when running through the JS cycle, check whether the annotation is in the selected array by comparing the JS Annotation "name" property and the IPXC_Annotation https://sdkhelp.pdf-xchange.com/vi ... ation_Name property.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
lidds
User
Posts: 510
Joined: Sat May 16, 2009 1:55 pm

Re: Get annot item when changing annot state

Post by lidds »

Hi Alex,

I have almost got it working, however I have noticed in the below section of the JS that it is only get the annotation on page "0" (zero), or does this mean the active page?

Code: Select all

        JS.AppendLine("var annots = this.getAnnots({")
        JS.AppendLine("nPage: 0,")
        JS.AppendLine("nSortBy: ANSB_Author,")
        JS.AppendLine("bReverse: true")
        JS.AppendLine("});")
Thanks

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

Re: Get annot item when changing annot state

Post by Sasha - Tracker Dev Team »

Hello Simon,

Here's the quote from the JS Specification:
nPage
(optional) A 0-based page number. If specified, gets only annotations on the given page. If not specified, gets annotations that meet the search criteria from all pages.
Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Post Reply