Skip to main content
Participant
February 21, 2022
Question

Delete comment on specific page using Javascript action

  • February 21, 2022
  • 2 replies
  • 469 views

Could anyone please assist me with the following: 

 

Goal:

I would like to adapt the below Javascript action, it should only delete any comment on the same page as the button (where executed) that has a specific author. 

 

My effort so far

this.syncAnnotScan();
var annots = this.getAnnots();

if (annots!=null) {
for (var i=annots.length-1; i>=0; i--) {
           if (annots[i].author == "JonDoe" )
              annots[i].destroy(); 
          }
}

 

Many thanks

 

 

This topic has been closed for replies.

2 replies

try67
Community Expert
Community Expert
February 22, 2022

Change this line:

var annots = this.getAnnots();

To this:

var annots = this.getAnnots({nPage: event.target.page});

The rest can stay the same.

BarlaeDC
Community Expert
Community Expert
February 22, 2022

Hi,

 

You should be able to use the page property, so you get the page from the button that was clicked and then you check that against the annot.page property, which tells you which page the annot is on.

something like

if ((annots[i].page == button.page) && (annots[i].author == "JonDow")){

 

Hope this helps

Participant
February 22, 2022

Completely brilliant, many thanks!

 

I have a button on several pages, hence:

 

Page1Button

var button = this.getField("Purge01");

[...]

 

Page5Button

var button = this.getField("Purge05");

[...]

 

Consequently I will need to individually 'hard code' each this.getField when defining the button variable.

Is there a way of avoiding this?

 

Best regards

 

 

 

Thom Parker
Community Expert
Community Expert
February 22, 2022

There is no need to use "getField" to acquire the button object. The button object where the code is being run is provided by the event object, i.e., event.target

Always check the Acrobat JavaScript Reference first:

https://opensource.adobe.com/dc-acrobat-sdk-docs/acrobatsdk/html2015/index.html#t=Acro12_MasterBook%2FJS_API_AcroJS%2Fevent_properties.htm%23TOC_targetbc-17&rhtocid=_6_1_8_27_4_16

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often