Script to Export Multiple PDFs at Once

Community Beginner ,
Apr 19, 2018

Copy link to clipboard

Copied

Hi All

I’m trying to find out how to export two PDF's at once from Indesign CC. I'm aiming to get 1 PDFx-1a PDF (High res with crop and bleed) and 1 smallest File Size (Cropped, no marks)? Could you point me in the right direction or if anyone has a working script I could use that would be amazing. My brain is going to fall out my ears.

Many thanks

Rahul

TOPICS
Scripting

Views

5.2K

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Adobe Community Professional ,
Apr 19, 2018

Copy link to clipboard

Copied

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Community Beginner ,
Apr 20, 2018

Copy link to clipboard

Copied

Thank you however I've tried this but the coding is incorrect. Could you resupply it on here? I keep getting an error with it.

Want to test this today 20th April if possible. Many thanks.

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Most Valuable Participant ,
Apr 20, 2018

Copy link to clipboard

Copied

Why not share the error? It may help us help you.

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Community Beginner ,
Apr 20, 2018

Copy link to clipboard

Copied

Got an error with it - I don't know anything about scripts, so any help or reconfiguration would be amazing!

// BS"D

// All rights reserved (c) 2015 by Id-Extras.com

// Free to use and modify but do not delete this copyright attribution.

// This script will export 2 pdfs of the current document

// Choose the PDF presets by altering their names below

// The second PDF gets a suffix added to its name.

// Modify the line below beginning name2 = to change the suffix.

// For more InDesign scripts: www.Id-Extras.com

d = app.activeDocument;

// Here you can choose the PDF preset

preset1 = app.pdfExportPresets.itemByName("200dpi");

preset2 = app.pdfExportPresets.itemByName("300dpi");

if (!(preset1.isValid && preset2.isValid)){

alert("One of the presets does not exist. Please check spelling carefully.");

exit();

}

if (d.saved){

thePath = String(d.fullName).replace(/\..+$/, "") + ".pdf";

thePath = String(new File(thePath).saveDlg());

}

else{

thePath = String((new File).saveDlg());

}

thePath = thePath.replace(/\.pdf$/, "");

name1 = thePath.replace(/AW$/, "LR")+".pdf";

name2 = thePath.replace(/AW$/, "HR") +".pdf";

d.exportFile(ExportFormat.PDF_TYPE, new File(name1), false, preset1);

d.exportFile(ExportFormat.PDF_TYPE, new File(name2), false, preset2);

Screen Shot 2018-04-20 at 09.26.33.png

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Adobe Community Professional ,
Apr 20, 2018

Copy link to clipboard

Copied

Looks as if you're treating this as an AppleScript. But it's JavaScript.

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Community Beginner ,
Apr 20, 2018

Copy link to clipboard

Copied

Hi Peter thanks for this. If it does work - I know its a silly question but how do I make this work with indesign? I know nothing about scripts - apple or java. Does this script work?

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Adobe Community Professional ,
Apr 20, 2018

Copy link to clipboard

Copied

Copy the script to InDesign's script folder, then run it from InDesign's Scripts panel. See here for details:

https://indesignsecrets.com/how-to-install-scripts-in-indesign.php

P.

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Community Beginner ,
Apr 20, 2018

Copy link to clipboard

Copied

Peter - great work - however can you tell me what im doing wrong. I'm almost there but not sure about the characters for the indesign pdf presets.

d = app.activeDocument;

// Here you can choose the PDF preset

preset1 = app.pdfExportPresets.[HighQualityPrint]("300dpi");

preset2 = app.pdfExportPresets.[Smallest File Size]("100dpi");

if (!(preset1.isValid && preset2.isValid)){

alert("One of the presets does not exist. Please check spelling carefully.");

exit();

}

if (d.saved){

thePath = String(d.fullName).replace(/\..+$/, "") + ".pdf";

thePath = String(new File(thePath).saveDlg());

}

else{

thePath = String((new File).saveDlg());

}

thePath = thePath.replace(/\.pdf$/, "");

name1 = thePath.replace(/AW$/, "LR")+".pdf";

name2 = thePath.replace(/AW$/, "HR") +".pdf";

d.exportFile(ExportFormat.PDF_TYPE, new File(name1), false, preset1);

d.exportFile(ExportFormat.PDF_TYPE, new File(name2), false, preset2);Screen Shot 2018-04-20 at 15.32.17.png

Cheers for your help so far, greatly appreciated.

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Adobe Community Professional ,
Apr 20, 2018

Copy link to clipboard

Copied

You'll have to specify PDF presets that exist on your disk. This one:

preset1 = app.pdfExportPresets.[HighQualityPrint]("300dpi");

should be this:

preset1 = app.pdfExportPresets.item ('[High Quality Print]');

and for preset2 you should use a similar format.

(mind the spaces). The ones in Ariel's script are specific for his system (sorry, Ariel, I seem to have hijacked this thread. . .)

P.

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Community Beginner ,
Apr 20, 2018

Copy link to clipboard

Copied

Okay - so the script worked! Yay! however its only creating one pdf - not two and its not renaming _LR _HR. I dont have a clue why it's working completley. Ive created two presets myself Print 1 and Lowres as test presets. Only one is working. See Code. I'm happy to wait on this, but just really need it by the end of next week. So close I can feel it!

d = app.activeDocument;

// Here you can choose the PDF preset

preset1 = app.pdfExportPresets.item ('Print1');

preset2 = app.pdfExportPresets.item ('Lowres');

if (!(preset1.isValid && preset2.isValid)){

alert("One of the presets does not exist. Please check spelling carefully.");

exit();

}

if (d.saved){

thePath = String(d.fullName).replace(/\..+$/, "") + ".pdf";

thePath = String(new File(thePath).saveDlg());

}

else{

thePath = String((new File).saveDlg());

}

thePath = thePath.replace(/\.pdf$/, "");

name1 = thePath.replace(/AW$/, "LR")+".pdf";

name2 = thePath.replace(/AW$/, "HR") +".pdf";

d.exportFile(ExportFormat.PDF_TYPE, new File(name1), false, preset1);

d.exportFile(ExportFormat.PDF_TYPE, new File(name2), false, preset2);

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Community Beginner ,
Apr 23, 2018

Copy link to clipboard

Copied

Okay - so the script worked! Yay! however its only creating one pdf - not two and its not renaming _LR _HR. I dont have a clue why it's working completly. Ive created two presets myself Print 1 and Lowres as test presets. Only one is working. See Code. I'm happy to wait on this, but just really need it by the end of this week. So close I can feel it!

d = app.activeDocument;

// Here you can choose the PDF preset

preset1 = app.pdfExportPresets.item ('Print1');

preset2 = app.pdfExportPresets.item ('Lowres');

if (!(preset1.isValid && preset2.isValid)){

alert("One of the presets does not exist. Please check spelling carefully.");

exit();

}

if (d.saved){

thePath = String(d.fullName).replace(/\..+$/, "") + ".pdf";

thePath = String(new File(thePath).saveDlg());

}

else{

thePath = String((new File).saveDlg());

}

thePath = thePath.replace(/\.pdf$/, "");

name1 = thePath.replace(/AW$/, "LR")+".pdf";

name2 = thePath.replace(/AW$/, "HR") +".pdf";

d.exportFile(ExportFormat.PDF_TYPE, new File(name1), false, preset1);

d.exportFile(ExportFormat.PDF_TYPE, new File(name2), false, preset2);

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Adobe Community Professional ,
Apr 23, 2018

Copy link to clipboard

Copied

Looks as if the script expects the names of the InDesign files to end in AW. Try this:

name1 = thePath + "LR.pdf";

name2 = thePath + "HR.pdf";

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Community Beginner ,
Apr 23, 2018

Copy link to clipboard

Copied

Fantastic - Thanks very much for your help! Greatly appreciated!

Rahul

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Adobe Community Professional ,
Apr 23, 2018

Copy link to clipboard

Copied

Thanks for the help, Peter!

The script that rahul1976 is posting here has been modified (possibly by me for someone else). The original version on the website that I linked to initially should work fine as is (see my initial post above).

Ariel

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
New Here ,
Nov 19, 2018

Copy link to clipboard

Copied

Hello

Im looking for a way to iprove this script a little - that it will

- save pdfs in current indd document location

- add active layer name to output name - filename_layername_LR

anyone could help me with it ?

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Participant ,
Nov 19, 2018

Copy link to clipboard

Copied

Hello

Im looking for a way to iprove this script a little - that it will

- save pdfs in current indd document location

- add active layer name to output name - filename_layername_LR

anyone could help me with it ?

d = app.activeDocument;

preset1 = app.pdfExportPresets.itemByName("[PDF/X-1a:2001]");

preset2 = app.pdfExportPresets.itemByName("[Smallest File Size]");

if (!(preset1.isValid && preset2.isValid))

{

     alert("One of the presets does not exist. Please check spelling carefully.");

     exit();

}

thePath = d.filePath + "/" + d.name.replace(".indd", "") + "_" + d.activeLayer.name;

name1 = thePath + "_HR.pdf";

name2 = thePath + "_LR.pdf";

//export PDFs as Background Tasks

d.asynchronousExportFile(ExportFormat.PDF_TYPE, new File(name1), false, preset1); //Hi-Res PDF

d.asynchronousExportFile(ExportFormat.PDF_TYPE, new File(name2), false, preset2); //Lo-Res PDF

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
New Here ,
Nov 23, 2018

Copy link to clipboard

Copied

Thank you very much. it is working, you've made my day

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Community Beginner ,
Dec 06, 2018

Copy link to clipboard

Copied

This is freaking fantastic!! I adjusted the code (below) to save out 3 PDFs at once and it works. YAY! What a time saver.

// BS"D

// All rights reserved (c) 2015 by Id-Extras.com

// Free to use and modify but do not delete this copyright attribution.

// This script will export 3 pdfs of the current document

// Choose the PDF presets by altering their names below

// The second PDF gets a suffix added to its name.

// Modify the line below beginning name2 = to change the suffix.

// For more InDesign scripts: www.Id-Extras.com

d = app.activeDocument;

// Here you can choose the PDF preset

preset1 = app.pdfExportPresets.itemByName("PRINT");

preset2 = app.pdfExportPresets.itemByName("PRESS");

preset3 = app.pdfExportPresets.itemByName("[Smallest File Size]");

if (!(preset1.isValid && preset2.isValid)){

alert("One of the presets does not exist. Please check spelling carefully.");

exit();

}

if (d.saved){

thePath = String(d.fullName).replace(/\..+$/, "") + ".pdf";

thePath = String(new File(thePath).saveDlg());

}

else{

thePath = String((new File).saveDlg());

}

thePath = thePath.replace(/\.pdf$/, "");

name1 = thePath+"_PRINT.pdf";

// Here you can set the suffix at the end of the name

name2 = thePath+"_PRESS.pdf";

name3 = thePath+"_DIGITAL.pdf";

d.exportFile(ExportFormat.PDF_TYPE, new File(name1), false, preset1);

d.exportFile(ExportFormat.PDF_TYPE, new File(name2), false, preset2);

d.exportFile(ExportFormat.PDF_TYPE, new File(name3), false, preset3);

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Explorer ,
Apr 03, 2019

Copy link to clipboard

Copied

hi,

Can the output pdf not override another pdf with the same name?

I have two files, when the name is stripped with regex, ends up with the same file name. When I export the pdfs:

with...

doc.asynchronousExportFile(ExportFormat.PDF_TYPE, new File(name2), false, preset2);

i get: Cannot save to the file because it is in use by one of more background tasks/

---because the first pdf is being generated by indesign.---

if i do,

doc.exportFile(ExportFormat.PDF_TYPE, new File(name2), false, preset2);

It just overwrites the first file with the second file.

Can it check for the existence of a file name and append a number? instead of replacing the first pdf.

i think a file name check has to be created at the name2

name2 = thePath+ ".pdf"; 

or is there an easier way? instead of new File(name2)...

any pointer would be appreciated.

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Participant ,
Apr 03, 2019

Copy link to clipboard

Copied

Here is an example that will export the current document as Test.pdf on the desktop. If the file(s) already exists it will add an counter: Test_1.pdf, Test_2.pdf, ...

var myPDFpreset = app.pdfExportPresets[0];

var doc = app.activeDocument;

var saveFolder = "~/desktop/";

       

var name = "Test";

var versionCounter = 1;

var pdf_fullname = new File (saveFolder + name + ".pdf");

while (pdf_fullname.exists)

    {

        pdf_fullname = File (saveFolder + name + "_" + versionCounter + ".pdf");

        versionCounter++;

    }

doc.asynchronousExportFile(ExportFormat.PDF_TYPE, pdf_fullname, false, myPDFpreset);

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Explorer ,
Apr 03, 2019

Copy link to clipboard

Copied

thank you!

i can adapt this to my needs.

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Participant ,
Apr 03, 2019

Copy link to clipboard

Copied

fyi:

when I omit the while part in my sample script it will overwrite the existing file without any problems when using the asynchronousExportFile function. I don't know why it doesn't work in your own script.

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Explorer ,
Apr 06, 2019

Copy link to clipboard

Copied

My same-named pdfs are created almost simultaneously, almost within the same second—as they are batched.

it works now with the ExportFile, the only downside is that it locks up InDesign. Which I can live with.

If i can insert a pause or a event listener, then maybe I can use asynchronousExportFile.

I might also be able to use asynchronousExportFile if the same named pdfs are not in the queue in a sequential order Like when these same named pdfs are part of a larger group, I think indesign prints them randomly.

Or print one set first, then the other set.

An even listener might be the more elegant approach, i need to look into it.

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
New Here ,
Nov 05, 2019

Copy link to clipboard

Copied

Anyway to add to the script so that I can identify which page numbers I would like to print? The current script runs the entire document. IE: We save all the business cards for Company X into one file. When someone submits a business card order, we export the one name to pdf. 

Likes

Translate

Translate

Report

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