• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Document.asynchronousExportFile - can't close document after export

New Here ,
Apr 23, 2017 Apr 23, 2017

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.

TOPICS
Scripting

Views

337

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Apr 23, 2017 Apr 23, 2017

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 23, 2017 Apr 23, 2017

Copy link to clipboard

Copied

LATEST

_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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines