Skip to main content
Participant
November 16, 2022
Answered

How to create a paragraph with difference font format by script/DOM?

  • November 16, 2022
  • 2 replies
  • 388 views

Dear All,

 

Is it possible to create a paragraph by Indesign script / DOM as below format?

 

Chapter One - Sample

 

Regards!
Brian 

 

This topic has been closed for replies.
Correct answer Manan Joshi

Hi @BrianLam2022,

Yes we can do that using scripting and much more. However, there are lots of ways to get this done, a simple approach is to use styles and apply them explicitly.

Create two styles, CS1(character style) for red color text, PS1(paragraph style) for the remaining text. Then create a text frame, select it and execute the following code

 

 

var a = app.selection[0]
a.insertionPoints[-1].appliedParagraphStyle = "PS1"
a.insertionPoints[-1].appliedCharacterStyle = "CS1"
a.contents = "Chapter One - "
a.insertionPoints[-1].appliedCharacterStyle = app.documents[0].characterStyles[0]
a.insertionPoints[-1].contents = "Sample"

 

 

In addition to this you could also use Grep style if you have some defined logic to identify the text that has to be applied with the character style.

-Manan

2 replies

Participant
November 16, 2022

Hi Manan, Thank you for your quick reply. 🙂

Manan JoshiCommunity ExpertCorrect answer
Community Expert
November 16, 2022

Hi @BrianLam2022,

Yes we can do that using scripting and much more. However, there are lots of ways to get this done, a simple approach is to use styles and apply them explicitly.

Create two styles, CS1(character style) for red color text, PS1(paragraph style) for the remaining text. Then create a text frame, select it and execute the following code

 

 

var a = app.selection[0]
a.insertionPoints[-1].appliedParagraphStyle = "PS1"
a.insertionPoints[-1].appliedCharacterStyle = "CS1"
a.contents = "Chapter One - "
a.insertionPoints[-1].appliedCharacterStyle = app.documents[0].characterStyles[0]
a.insertionPoints[-1].contents = "Sample"

 

 

In addition to this you could also use Grep style if you have some defined logic to identify the text that has to be applied with the character style.

-Manan

-Manan