Copy link to clipboard
Copied
I have this function:
function __exportPdf(doc, file, preset){
pdfPreset = app.pdfExportPresets.item(preset);
// doc.exportFile(ExportFormat.pdfType, file, false, pdfPreset);
// doc.close(SaveOptions.no);
__makeListener(doc);
doc.asynchronousExportFile(ExportFormat.pdfType, file, false, pdfPreset);
}
and this one:
function __makeListener(_d){
var afterExportListener = _d.eventListeners.itemByName("afterExport");
if (afterExportListener.isValid) {
afterExportListener.remove();
}
_d.addEventListener("afterExport", function(event) {
// event parent is document to close
alert(event.parent);
event.parent.close(SaveOptions.no);
}).name = "afterExport";
}
alert fires, but document is still open.
I have a lot of indd files, large and little ones, and i want to open another one when previous one is being exported.
And it works. But I can't close document of file already exported.
Copy link to clipboard
Copied
If you are defining _d as activeDocument or documents[0] then try defining _d as itemByID
_d = app.documents.itemByID(app.documents[0].id);
It might sound silly but give it a go
Copy link to clipboard
Copied
_d is reference to var DOCUMENT
var DOCUMENT = app.documents.add(true);
/* some code here */
__exportPdf(DOCUMENT, pdfFile, '2017_001');
but I'll try the way you gave