How do I format the font styles in javascript to InDesign Doc from Switch?

Post Reply
neecerp
Newbie
Posts: 14
Joined: Tue Jun 05, 2012 9:21 pm

How do I format the font styles in javascript to InDesign Doc from Switch?

Post by neecerp »

Using Javascript to open InDesign, read XML and create a pdf out of Switch.

How do I format portions of the text that is written. Here is what I have so far....but it seems to only pick up the paragraph styles that are in Indesign???









//This is a command javascript so Switch takes care of opening the file

//$error and $doc come from Switch opening the file



//Start all scripts with this basic error routine

if(($error == null) && ($doc != null))

{

try

{

//Declare variables available to javascript $doc is the file opened by switch and replaces app.activeDocument

var H = $doc.documentPreferences.pageHeight;

var W = $doc.documentPreferences.pageWidth;

$doc.viewPreferences.rulerOrigin = RulerOrigin.pageOrigin;





//Pickup data from switch from the 5 arguments

var arg1 = $arg1;

var arg2 = $arg2;

var arg3 = $arg3;

var arg4 = $arg4;

var arg5 = $arg5;



with ($doc.pages.item(0)){

with (textFrames.add()){

geometricBounds = [16, 3, H -6, W -.5];

insertionPoints.item(0).contents = "Magento Order ID - " +arg1+ arg2;

paragraphs.item(0).justification = Justification.leftAlign;

}

}

//Declare variables available to javascript $doc is the file opened by switch and replaces app.activeDocument

var H = $doc.documentPreferences.pageHeight;

var W = $doc.documentPreferences.pageWidth;

$doc.viewPreferences.rulerOrigin = RulerOrigin.pageOrigin;





//Pickup data from switch from the 5 arguments

var arg1 = $arg1;

var arg2 = $arg2;

var arg3 = $arg3;

var arg4 = $arg4;

var arg5 = $arg5;



with ($doc.pages.item(0)){

with (textFrames.add()){

geometricBounds = [45, 3, H -6, W -.5];

insertionPoints.item(0).contents = arg3+ "r" +arg4+ " This is a test-"+ arg5;

paragraphs.item(0).justification = Justification.leftAlign;



}

}

function createStyles(){

var stlHead = g.doc.paragraphStyles.add();

stlHead.name = "MageDocID";

try{stlHead.appliedFont = "Arial Black";}catch(e){}

stlHead.pointSize = "14 pt";

stlHead.startParagraph = StartParagraph.nextPage;



var stlAuthor = g.doc.paragraphStyles.add();

stlAuthor.name = "PSorderID";

try{stlAuthor.appliedFont = "Arial"}catch(e){}

stlAuthor.pointSize = "14 pt";

stlAuthor.spaceAfter = "9 pt";



var stlpara = g.doc.paragraphStyles.add();

stlPara.name = "PSPickID";

try{stlPara.appliedFont = "Code39 Regular"}catch(e){};

stlPara.pointSize = "36 pt";

stlPara.spaceAfter = "36 pt";

}



function mapTags(){

g.doc.loadXMLTags(File("/Users/switchmac/Desktop/Indesign Add Text from XML 2/MagentoFatXML.xml"));

g.doc.xmlTags.item("Root").name = "MageDocID";

g.doc.xmlImportMaps.add("MageDocID", "MageDocID");

g.doc.xmlImportMaps.add("PSPickID", "PSPickID");

g.doc.xmlImportMaps.add("MageOrderID", "MageOrderID");

g.doc.mapXMLTagsToStyles ();

}

//This is a command javascript so Switch will take care of saving the file and closing

}

catch(theError)

{

$doc.close(SaveOptions.no);

$error = theError.description;

}

}
dkelly
TOP CONTRIBUTOR
Posts: 628
Joined: Mon Nov 29, 2010 8:45 pm
Location: Alpharetta GA USA
Contact:

How do I format the font styles in javascript to InDesign Doc from Switch?

Post by dkelly »

Check out Indesign scripting forum @ http://forums.adobe.com/community/indes ... _scripting
Post Reply