Remove rectangle annotation

PDF-XChange Viewer SDK for Developer's
(ActiveX and Simple DLL Versions)

Moderators: PDF-XChange Support, Daniel - PDF-XChange, Chris - PDF-XChange, Sean - PDF-XChange, Vasyl - PDF-XChange, Ivan - Tracker Software, Stefan - PDF-XChange

KarlTH
User
Posts: 57
Joined: Mon Aug 01, 2005 2:33 pm

Remove rectangle annotation

Post by KarlTH »

Hello Support-Team,

how can I remove a rectangle annotation or other annotations by name? Did not find anything in the documentation.
An example (pseudocode) will be great!

Code: Select all

'Get annot name
AxPDFXViewCtrl.GetProperty(e.name + ".Name", oDataOut)
strAnnotName = DirectCast(oDataOut, String)

Thanks,

Karl
User avatar
Stefan - PDF-XChange
Site Admin
Posts: 19868
Joined: Mon Jan 12, 2009 8:07 am

Re: Remove rectangle annotation

Post by Stefan - PDF-XChange »

Hi Karl,

You would need to use JS (RunJavaScript() method) for this.
e.g.: Remove all "FreeText" annotations on page 0.

Code: Select all

var annots = this.getAnnots({ nPage:0 }); 
for (var i = 0; i < annots.length; i++) 
if (annots[i].type == "FreeText") annots[i].destroy();
KarlTH
User
Posts: 57
Joined: Mon Aug 01, 2005 2:33 pm

Re: Remove rectangle annotation

Post by KarlTH »

Hello Stefan,

I was afraid you will say that. :shock: JavaScript
I will try it and let you know if I was successfull!


THANK YOU

Karl
User avatar
Stefan - PDF-XChange
Site Admin
Posts: 19868
Joined: Mon Jan 12, 2009 8:07 am

Re: Remove rectangle annotation

Post by Stefan - PDF-XChange »

:)
KarlTH
User
Posts: 57
Joined: Mon Aug 01, 2005 2:33 pm

Re: Remove rectangle annotation

Post by KarlTH »

Hello Stefan,

I did it but JavaScript debugging is catastrophic :evil: and here is my code in VB .NET:

Code: Select all

Private Sub AxPDFXViewCtrl_OnEvent(sender As Object, e As AxPDFXCviewAxLib._IPDFXCviewEvents_OnEventEvent) Handles AxPDFXViewCtrl.OnEvent
                AxPDFXViewCtrl.GetProperty(e.name + ".Temp", oDataOut)
                iAnnotHasBeenCreated = DirectCast(oDataOut, Integer)

                If iAnnotHasBeenCreated = 0 Then '// (isTemp != 0) - the creation of annot isn't finished

                    AxPDFXViewCtrl.GetProperty(e.name + ".Name", oDataOut)
                    strAnnotName = DirectCast(oDataOut, String)

                    strJavaCmd = "var annots = this.getAnnots({ nPage:0 });" + Environment.NewLine
                    strJavaCmd += "for (var i = 0; i < annots.length; i++){" + Environment.NewLine
                    strJavaCmd += "if (annots[i].name == """ + strAnnotName + """) annots[i].destroy();" + Environment.NewLine
                    ' ONLY FOR DEBUGGING - strJavaCmd += "console.println(annots[i].name);" + Environment.NewLine
                    strJavaCmd += "}"

                    AxPDFXViewCtrl.RunJavaScript(strJavaCmd)
                End If
End Sub
Would be nice if you include a "RemoveAnnot" method in your API in one of the next releases.


Thank you so much

Karl
User avatar
Stefan - PDF-XChange
Site Admin
Posts: 19868
Joined: Mon Jan 12, 2009 8:07 am

Re: Remove rectangle annotation

Post by Stefan - PDF-XChange »

Hi Karl,

Glad that you made it work, and thanks for sharing your code! Hope it would be useful to other developers as well.

As for your request for a new method - I am not going to make any promises as there's already a way to achieve that with your "beloved" JS :)

Regards,
Stefan
KarlTH
User
Posts: 57
Joined: Mon Aug 01, 2005 2:33 pm

Re: Remove rectangle annotation

Post by KarlTH »

Hi Stefan,

sounds good! :)
Now it is working but would be nice if I can replace this lines of Java code at the next Refactoring.


Thank you so much

Karl
User avatar
Stefan - PDF-XChange
Site Admin
Posts: 19868
Joined: Mon Jan 12, 2009 8:07 am

Re: Remove rectangle annotation

Post by Stefan - PDF-XChange »

:)