Create InDesign document with an XML

Post Reply
Passion
Newbie
Posts: 1
Joined: Fri Apr 20, 2012 10:47 am

Create InDesign document with an XML

Post 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.
dkelly
TOP CONTRIBUTOR
Posts: 658
Joined: Mon Nov 29, 2010 8:45 pm
Location: Alpharetta GA USA
Contact:

Create InDesign document with an XML

Post 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.
Post Reply