Page 1 of 1
Create InDesign document with an XML
Posted: Fri Apr 20, 2012 10:50 am
by Passion
Hello,
How to create an InDesign document from an XML information (width/height).
Parsing XML is OK but I don't find how to create the InDesign document with scripting.
Create InDesign document with an XML
Posted: Fri Apr 20, 2012 4:47 pm
by dkelly
Creating an Indesign document is pretty easy with Javascript.
var myDoc:Document = app.documents.add();
myDoc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.POINTS;
myDoc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.POINTS;
myDoc.documentPreferences.pageHeight = 612;
myDoc.documentPreferences.pageWidth = 792;
myDoc.documentPreferences.pageOrientation = PageOrientation.PORTRAIT;
myDoc.documentPreferences.pagesPerDocument = 1;
You can retrieve values from Switch via the $arg[1-5] variables and tell Switch where you saved the Indesign document via the $outfolder and $outfiles variables.
// create the document
var myDoc:Document = app.documents.add();
myDoc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.POINTS;
myDoc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.POINTS;
myDoc.documentPreferences.pageHeight = $arg1;
myDoc.documentPreferences.pageWidth = $arg2;
myDoc.documentPreferences.pageOrientation = PageOrientation.PORTRAIT;
myDoc.documentPreferences.pagesPerDocument = 1;
// now save it
var fn = $outfolder + "/newDoc.idd";
myDoc.save(fn);
// and finally tell Switch what files we created
$outfiles = fn;
Config $arg1 and $arg2 to contain the width and height of the document (from your XML) and set the script above as the "open" script for the Indesign configurator because you don't have a file to pass to Indesign to open.