Skip to content

Instantly share code, notes, and snippets.

@Neoglyph
Created May 24, 2018 12:59
Show Gist options
  • Save Neoglyph/6e98bdf7959b0f8d457cf49b08d489e5 to your computer and use it in GitHub Desktop.
Save Neoglyph/6e98bdf7959b0f8d457cf49b08d489e5 to your computer and use it in GitHub Desktop.
InDesign Import XML
main ()
function main () {
// create a path for a file object
var curFile = File ( "~/Desktop/myTemplate.indt" );
// check if the file exists
if (!curFile.exists) {
alert ( "no template!" );
exit();
}
// open the file
var curDoc = app.open( curFile );
// create a new file object
var inddFile = new File ( curFile.parent + "/myName.indd" );
// save the file
curDoc.save( inddFile );
//XML import
curDoc.importXML( File("~/Desktop/myName.xml") );
// root-element
var root = curDoc.xmlElements[0];
// do your xml stuff, e.g.
var category = root.xmlElements[0]; // for more categories it needs a loop
var product1 = category.xmlElements.itemByName('productname');
product1.placeXML ( curTextFrame1 ); // there must be a textFrame!
// create a new file object
var pdfFile = new File ( curFile.parent + "/myName.pdf" );
// export to pdf
curDoc.exportFile( ExportFormat.PDF_TYPE, pdfFile );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment