-
1. Re: Close document after background export to PDF
Ten A Jan 6, 2012 4:53 PM (in response to BreachofMind)Hi Mike.
Here is an example of capture export event:
#targetengine session
(function() {
app.addEventListener("afterExport", function(evnt) {
var task, listener;
task = app.idleTasks.add({ name: "exportPDF", sleep: 1000});
listener = task.addEventListener(IdleEvent.ON_IDLE,
function(ev) {
listener.remove();
task.remove();
if (/Adobe\sPDF/.test(evnt.format)){
app.activeDocument.close (SaveOptions.YES);
}
});
}).name = "exportPDF";
alert("custom exporter installed.");
}());
If you want stop listener, run below:
#targetengine "session"
myListener = app.eventListeners.itemByName("exportPDF");
if (myListener.isValid) {
myListener.remove();
alert ("custom exporter removed." )
}
...or you can disable background export. You can read as reference below:
http://forums.adobe.com/message/3689090#3689090
Ten.
-
2. Re: Close document after background export to PDF
Laubender Jan 7, 2012 1:11 AM (in response to Ten A)@Ten: the "old" exportFile method is still available.
So, if you want to export to PDF without a background task you could do it like this:myDocument.exportFile ( ExportFormat.pdfType, File (desktopFolder.fsName+"/"+pdfFile), false ) myDocument.close();
But I think Mike did deliberately choose the "asynchronously" variety…
Uwe
-
3. Re: Close document after background export to PDF
BreachofMind Jan 12, 2012 7:45 AM (in response to Ten A)Heres my code:
#targetengine session
function Listen () {
app.addEventListener("afterExport", function(evt) {
var task = app.idleTasks.add ({name:"exportPDF", sleep: 1000});
var listener = task.addEventListener (IdleEvent.ON_IDLE, function(e) {
listener.remove();
task.remove();
if (/Adobe\sPDF/.test(evt.format)) {myDoc.close(SaveOptions.YES)};
});
}).name = "exportPDF";
alert ("Custom exporter installed.");
}
Listen();
myDoc.asynchronousExportFile(
ExportFormat.pdfType,
File (dirFolder.fsName + "/" + pdfFile),
false
)I was concerned that the "afterExport" class is not in the object model for InDesign CS5. I think that may be why the document is not closing after the export completes. Other than that, there are no errors...
-
4. Re: Close document after background export to PDF
BreachofMind Jan 12, 2012 8:46 AM (in response to Ten A)Actually I did get it to work! Nice. However, a warning appears after the document was closed saying "An attached script says an object was invalid". Why is that?
-
5. Re: Close document after background export to PDF
Ten A Jan 13, 2012 12:46 AM (in response to BreachofMind)Hi Mike.
Your code works fine in my environment. But I think better to kill Listener each time automatically.
#targetengine session
function Listen () {
app.addEventListener("afterExport", function(evt) {
var task = app.idleTasks.add ({name:"exportPDF", sleep: 1000});
var listener = task.addEventListener (IdleEvent.ON_IDLE, function(e) {
listener.remove();
task.remove();
if (/Adobe\sPDF/.test(evt.format)) {
myDoc.close(SaveOptions.YES);
app.eventListeners.itemByName("exportPDF").remove(); //kill listener.
//alert ("custom exporter removed.")
};
});
}).name = "exportPDF";
//alert ("Custom exporter installed.");
}
//my test parameters.
var myDoc = app.activeDocument;
pdfFile = "/test10.pdf";
Listen();
myDoc.asynchronousExportFile(
ExportFormat.pdfType,
File (pdfFile),
false
)
Event classes dropped from Object Model Viewer. But we can correct props ourself like below :
var str ="";
for (var a in Event) {
str += a + "\n";
}
alert(str);
But I think best way of reading Object Model, download and read Jongware's CHM file. Check below link.
http://forums.adobe.com/thread/668578
@Uwe : Thank you for your information.
Ten
-
6. Re: Close document after background export to PDF
John Hawkinson Jan 13, 2012 9:59 PM (in response to Ten A)Event classes dropped from Object Model Viewer. But we can correct props ourself like below :
var str ="";
for (var a in Event) {
str += a + "\n";
}
alert(str);
Eww!
Just use reflection:
alert(Event.reflect.properties.join("\n")); -
7. Re: Close document after background export to PDF
BreachofMind Jan 25, 2012 8:41 AM (in response to Ten A)This is really helpful.. I've been using it for awhile now. But, I'd like to make it better.
How would I go about creating a queue? Right now, when I try to export multiple documents at once, the script will only close the last document exported, and not the others. So, if I run the script each time on 3 documents, only the last one will close.
Ideally, I'd like to add these documents to a queue that will close them each as they finish. How would you go about doing that?
Cheers,
Mike
-
8. Re: Close document after background export to PDF
Ten A Jan 25, 2012 7:10 PM (in response to BreachofMind)Hi Mike,
We can do that, simply counting finished time. But regular variables lost value when functions finished.
So I try to use closure and it works, see below:
#targetengine session
function Listen (num) {
var flg = (function (){ //closure
var _f = 1;
return function(){return _f++;}
})();
app.addEventListener("afterExport", function(evt) {
var task = app.idleTasks.add ({name:"exportPDF", sleep: 1000});
var listener = task.addEventListener (IdleEvent.ON_IDLE, function(e) {
listener.remove();
task.remove();
if (/Adobe\sPDF/.test(evt.format)&&flg()>num) {
myDoc.close(SaveOptions.YES);
app.eventListeners.itemByName("exportPDF").remove();
}
});
}).name = "exportPDF";
}
//test
var myDoc = app.activeDocument;
var svLen = 3; //document length
Listen(svLen-1);
for (i=0;i<svLen;i++)
myDoc.asynchronousExportFile(ExportFormat.pdfType,File ("/test" + i + ".pdf"),false);
Ten
-
9. Re: Close document after background export to PDF
Mnietek May 20, 2013 7:48 AM (in response to Ten A)Hi Ten,
I can't get this to work....
Script is able to close only one document after exporting to pdf.
Also - when I open 3 different documents, script generates 3 the same pdfs from one of opened docs.



