Search code examples
pdfadobe-indesign

Looking for a faster way to batch export pdf:s in InDesign


I'm using this script (below) to batch export pdf:s from several indesign files for a task i do every week. The filenames are always the same, i'm using 8-10 different indd files to create 12-15 different pdf:s.

The script is set up like this:

//Sets variables for print and web presets
var myPDFExportPreset = app.pdfExportPresets.item("my-present-for-print-pdf");
var myPDFExportPreset2 = app.pdfExportPresets.item("my-preset-for-web-pdf");

//sample of one pdf exported first with print, then web pdf preset as two different files

var firstFileIntoPdfs = function(){

var openDocument= app.open(File("MYFILEPATH/firstfile.indd"));

    openDocument.exportFile(
        ExportFormat.pdfType,
        File("MYFILEPATH/print-pdfs/firstfile-print.pdf"),
        false, 
        myPDFExportPreset
    );

    openDocument.exportFile(
        ExportFormat.pdfType,
        File("MYFILEPATH/web-pdfs/firstfile-web.pdf"),
        false, 
        myPDFExportPreset2
    );
};

I'm defining all exports like the one above as named functions, some using only one of the presets, some two like the one above. I'm calling all these functions at the end of the file

firstFileIntoPdfs();
secondFileIntoPdfs();
thirdFileIntoPdfs();
fourthFileIntoPdfs();

and so on... ¨

The script is however quite slow, 10 files into 1 or 2 pdfs each, like the function above, can take 10 minutes. I don't think this is a CPU issue, what i noticed is that it seems like the script is waiting for the files in "firstFileIntoPdfs()" to be created, a process that takes some minutes, before proceeding to execute the next function. Then waiting again...

Selecting File -> Export manually you can set new files to be exported while the previous ones are still processing the pdf files, which to me has seemed faster than how this script is working. Manual clicking is however error prone and tedious, of course.

Is there a better way to write this batch export script than how i've done above, that would make all functions executed while pdfs from previous functions still are processed in the system? I'd like to keep them as separate functions in order to be able to comment out some when only needing certain specific pdf:s. (unless the process of exporting all becomes nearly as fast as exporting only 1 pdf).

I hope my question makes sense!


Solution

  • There is an asynch method available, replace exportFile with asynchrousExportFile:

    var openDocument= app.open(File("MYFILEPATH/firstfile.indd"));
    openDocument.asynchronousExportFile(
        ExportFormat.pdfType,
        File("MYFILEPATH/print-pdfs/firstfile-print.pdf"),
        false, 
        myPDFExportPreset
    );
    

    which use a background task