Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Javascript issues - For Loop breaking this.addAnnot

Explorer ,
Nov 04, 2022 Nov 04, 2022

I'm having a weird issue with my script.  I want to create a rectangle annotation (the one found in Comments > then the square icon in the ribbon, NOT a text box).  I set it to full page.  If I have the code below without the for loop and just manually set p to a number, it creates the rectangle at the page corresponding to the number as expected.  It also shows up in the comments section with all the correct properties set by the script (author, content, etc).  

 

Now I wanted to automate it to do this to all pages in the document by using a For loop for p.  However, it only creates the rectangle but none of the properties are applied and therefore Acrobat doesn't consider it a markup and I can't redact it because it doesn't show up in the Comment section as a markup.  Is there a way around this or is my code just messed up?

var re = /.*\/|\.pdf$/ig; 
var FileNM = this.path.replace(re,""); 
var Path = this.path; 

for (var p = 0; p < this.numPages; p++) { 
	var aRect = this.getPageBox("Crop",p); 
	var LeftPoint = aRect[0]
	var TopPoint = aRect[1]
	var RightPoint = aRect[2]
	var BottomPoint = aRect[3]
	var annot = this.addAnnot({ page: p, type: "Square", rect: [LeftPoint, TopPoint, RightPoint, BottomPoint], name: "Test", author: "Redact", contents: "Redaction",});
}
this.flattenPages()

 

TOPICS
General troubleshooting , How to , JavaScript
775
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
1 ACCEPTED SOLUTION
Community Expert ,
Nov 04, 2022 Nov 04, 2022

Remove the line

this.flattenPages();

 

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 04, 2022 Nov 04, 2022

Remove the line

this.flattenPages();

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 04, 2022 Nov 04, 2022
LATEST

Omg.  Thanks.  I can't believe I missed that.  Second Pair of eyes helped.  Have a good one.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines