JavaScript examples and a conditional text setup in Adobe FrameMaker.
It’s time to make an automated tool for some easy work: the script will set font styles and heading formatting on some DITA topics in FrameMaker. The script automatically loops through your topics, finds headings, and applies a predefined style to them.
JavaScript Script Example:
This script sets the font to “Arial” and applies the heading style to any text that matches the “Heading1 context” tag.
// JavaScript to format all headings in a FrameMaker document
var doc = app.ActiveDoc; // get the active document
var paragraphFormat = doc.ParagraphFormats.Item(“Heading1”); // style for Heading1
// Loop through all the Paragraphs in the document
for(var i=1; i<= doc.Paragraphs.Count; i++) {
var para = doc.Paragraphs.Item(i);
// Check if the paragraph is a Heading1
if (para.Format.Name == “Heading1”) {
// Set Heading1 paragraph to Arial font
para.TextFont = “Arial”;
// Apply Heading1 defined style
para.Format = paragraphFormat;
}
}
How to Run the Script?
- Open FrameMaker and have your DITA content opened.
- File > Scripts > Script Editor: Opens the JavaScript editor.
- Copy the script into the editor.
- Click Run to apply font and heading formatting to all headings found in the document.
What This Script Does:
- It applies to all Heading1 paragraphs found in the current document.
- The font for these headings is set to Arial.
- It ensures that Heading1 style is applied uniformly for all matching paragraphs.
