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
Post
by KarlTH » Thu Jun 06, 2013 2:23 pm
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
Stefan - PDF-XChange
Site Admin
Posts: 19868 Joined: Mon Jan 12, 2009 8:07 am
Post
by Stefan - PDF-XChange » Thu Jun 06, 2013 2:36 pm
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
Post
by KarlTH » Thu Jun 06, 2013 2:41 pm
Hello Stefan,
I was afraid you will say that.
JavaScript
I will try it and let you know if I was successfull!
THANK YOU
Karl
Stefan - PDF-XChange
Site Admin
Posts: 19868 Joined: Mon Jan 12, 2009 8:07 am
Post
by Stefan - PDF-XChange » Thu Jun 06, 2013 3:43 pm
KarlTH
User
Posts: 57 Joined: Mon Aug 01, 2005 2:33 pm
Post
by KarlTH » Mon Jun 10, 2013 7:08 am
Hello Stefan,
I did it but JavaScript debugging is catastrophic
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
Stefan - PDF-XChange
Site Admin
Posts: 19868 Joined: Mon Jan 12, 2009 8:07 am
Post
by Stefan - PDF-XChange » Mon Jun 10, 2013 11:02 am
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
Post
by KarlTH » Mon Jun 10, 2013 11:14 am
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
Stefan - PDF-XChange
Site Admin
Posts: 19868 Joined: Mon Jan 12, 2009 8:07 am
Post
by Stefan - PDF-XChange » Mon Jun 10, 2013 11:15 am