Skip to main content
Participant
February 26, 2020
Question

How to use Javascript in PDF to format all the free text annotation (such as bold)?

  • February 26, 2020
  • 1 reply
  • 1522 views

have a lot of PDF files with countless free text annotation. I try to use Javascript to batch modify the format of the annotation to make it bold and set the font to Times New Roman. I refer the detail API information in this (https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/AcrobatDC_js_api_reference.pdf). 

I tried the following method:

 

var annt = this.getAnnots(1)[0]app.alert(annt.textFont)annt.textFont = "TimesNewRomanPSMT"
var spans = new Array();spans[0] = new Object();spans[0].text = annt.contents;spans[0].textColor = color.red;spans[0].textSize = 24;spans[0].alignment = "center";spans[0].fontWeight = 800;  //set boldspans[0].textFont = "TimesNewRomanPSMT"annt.richContents = spans

This gave me the bold text, but the font changed to Arial and cannot set the font back to Times New Roman...

So, I tried another way...

 

var annt = this.getAnnots(1)[0]
var span = annt.richContents
span[0].fontWeight = 800  //set boldannt.richContents = span

However, this does nothing...

Is this a bug?

Can anyone suggest good methods to do this? It is difficult to change the format one by one... Thank a lot!

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
February 26, 2020

You have to re-apply the spans array to the richContents property of the Annotation at the end of your code.

See the first code you found.