I use InDesign CS6. I wrote a javascript to add an option into menu: it first imports an XML in a document, then removes empty pages. As run, before it actually imports an XML file, it removes empty pages. So there aren't enough pages for the XML.
How to excute these 2 functions as wanted? Here is my program:
var menuItem = "XML";
var smaTitle1 = "Import XML";
var sma1 = app.scriptMenuActions.add(smaTitle1);
// Add an Event Listener
sma1.addEventListener(
/*event type*/ 'onInvoke',
/*event handler*/ function(){
importXML(xmlPath);
}
);
sma1.addEventListener(
/*event type*/ 'afterInvoke',
/*event handler*/ function(){
// Remove empty pages
alert("remove pages");
removeEmptyPages();
}
);
function importXML(xmlPath){
if (app.documents.length != 0){
var myDocument = app.documents.item(0);
//import the entire XML structure in the document.
var myXMLImportPreferences = myDocument.xmlImportPreferences;
myXMLImportPreferences.allowTransform = false;
myXMLImportPreferences.ignoreWhitespace = true;
myXMLImportPreferences.removeUnmatchedExisting = false;
myXMLImportPreferences.importStyle = XMLImportStyles.MERGE_IMPORT;
myXMLImportPreferences.repeatTextElements = true;
var path = new File(xmlPath);
var file = path.openDlg("Importer XML", "XML:*.xml", false);
if (file != null) {
myDocument.importXML(file);
}
}
}
function removeEmptyPages(){
...
// a loop to remove empty pages
pages[i].remove();
...
}
No comments:
Post a Comment