AEM InDesign - Convert Bold Strong HTML Tags in Content Fragments RTE to InDesign Bold


This Post on AEM Content Fragments and InDesign talks about creating the integration and using Content Fragments on InDesign pages.

Following script provides additional code for converting the Bold/Strong html tags in CF RTE to InDesign specific bold

Demo | Github




function createPageItem(spread) {
var rect = spread.textFrames.add();

var y1 = 10; // upper left Y-Coordinate
var x1 = 10; // upper left X-Coordinate
var y2 = 50; // lower right Y-Coordinate
var x2 = 40; // lower right X-Coordinate

rect.geometricBounds = [y1, x1, y2, x2];

return rect;
}

function getPlaceSpread(document) {
var lastSpread = document.spreads.lastItem();

return lastSpread;
}

function getBoldStyle(document) {
var boldCharacterStyle = document.characterStyles.add();

boldCharacterStyle.appliedFont = app.fonts[6];

boldCharacterStyle.fontStyle = "Bold";

return boldCharacterStyle;
}

try {
var document = app.documents.add();

var spread = getPlaceSpread(document);

var rect = createPageItem(spread);

rect.contents = "This is a <strong>Strong Text</strong> in Indesign";

app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;

app.changeGrepPreferences.changeTo = "$3";

app.changeGrepPreferences.appliedCharacterStyle = getBoldStyle(document);

app.findGrepPreferences.findWhat = "(<strong(\\s.*)?>)(.+?)(</strong(\\s.*)?>)";

rect.changeGrep();

app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;

} catch (err) {
$.writeln(err)
}

No comments:

Post a Comment