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

New Here ,
Feb 25, 2020

Copy link to clipboard

Copied

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!

TOPICS
Acrobat SDK and JavaScript, Edit and convert PDFs, General troubleshooting, How to

Views

162

Likes

Translate

Translate

Report

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

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

New Here ,
Feb 25, 2020

Copy link to clipboard

Copied

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!

TOPICS
Acrobat SDK and JavaScript, Edit and convert PDFs, General troubleshooting, How to

Views

163

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Feb 25, 2020 0
try67 LATEST
Most Valuable Participant ,
Feb 26, 2020

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 26, 2020 0