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

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

New Here ,
Feb 25, 2020 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

Views

1.0K

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
community guidelines
Community Expert ,
Feb 26, 2020 Feb 26, 2020

Copy link to clipboard

Copied

LATEST

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.

Votes

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
community guidelines