July 2018 UPDATE: If you’re looking to export multiple PDFs, using multiple PDF export presets, into multiple folders, using super-flexible filenaming options (including filenames based on the contents of the page itself), our newly updated Extract Pages script is for you! Click here for all the details.
Back in May (2015), someone asked on the Adobe forum if there was a way to export 2 pdfs from InDesign at once, using different presets.
The answer was the following little script, which can be easily adapted to exported more than just 2 PDFs, using any existing PDF presets you like:
// 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("[High Quality Print]"); 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(); } 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+".pdf"; // Here you can set the suffix at the end of the name name2 = thePath+"_xx.pdf"; d.exportFile(ExportFormat.PDF_TYPE, new File(name1), false, preset1); d.exportFile(ExportFormat.PDF_TYPE, new File(name2), false, preset2);
Enjoy!
Roy Solorio
August 7, 2020 3:33 amSuch a simple bit, but that worked like a charm. Thanks Ariel.
Roy Solorio
August 1, 2020 8:54 amLove love love it. Was able to modify and get three count them three different flavored PDFs. Thanks.
Is there a snippet of code that exits the save dialog when the cancel button is selected?
Ariel
August 7, 2020 12:26 amHi Roy,
Glad you’re finding it useful. It’s very satisfying when you can put together yourself a script that works.
The basic idea with the save dialog is that if the user hits the Esc key to exit, or clicks on Cancel, the dialog returns null.
So you would want to test that thePath variable is not null:
Hope that helps!
Ariel
Andy
August 12, 2020 12:51 pmHi Ariel
A while ago I paid you to sort this script for me (see the comments above) but with updates and re-installs of indesign the script stopped working.
Do you think you could provide me with a fresh script? My Presets are “LR” and “HR” and the existing indesign document would end with “AW.indd”. Each preset would save out with LR or HR instead of the AW letters accordingly if you remember.
Let me know if you’re interested. Completely happy to pay for your service again.
🙂
I’m on v15.1.1 on a Mac if that helps.
Ariel
August 12, 2020 4:03 pmHi Andy,
I just had a quick look, there is nothing in the script that would make it stop working with recent versions of InDesign.
My guess is that it’s a permissions issue on the Mac that is preventing the script from saving to the requested folder.
Ariel
Daniel
November 22, 2019 5:14 pmhi
This excellent script have one problem for us.
If I manually export pdf for example page 72, indesign pdf export dialog remember this. After running this script only page 72 is exported.
Can you modify this script to reset pdf dialog to “all” pages?
Ariel
November 25, 2019 7:23 pmAdding this line to the start of the script should do the trick:
app.pdfExportPreferences.pageRange = “”;
Alan
January 24, 2019 6:05 pmNot so clear to a beginner!
Thanks anyway.
Alan
January 23, 2019 10:35 pmHello! A few questions as I’m trying to modify this code for my own use.
– Is there a way to change the file output file names so there is a prefix at the beginning rather than a suffix and the end? I’ve tried the following:
name2 = “prefix-“+thePath+”.pdf”;
but I get an error message indicating that it’s trying to save to a folder named “prefix” instead of adding the string to the beginning of the file name.
– This may be beyond the scope of this script, but could it be modified to extract each page in a document individually?
Ariel
January 24, 2019 1:07 amHi Alan,
If you just add the prefix to the beginning of the variable thePath, you are adding it to the beginning of the path, which is clearly wrong. You would be wanting to add it to the beginning of the file name only, not the entire path.
To save as separate pages is a little more complicated.
To me it sounds like you could benefit from the full version of Extract Pages, which would let you easily do both these things and a lot more…
Ariel
January 4, 2019 4:31 pmHi Scott,
InDesign’s Folder object has a (wait for it) “exists” property.
So in principal you would just write:
In the original script I posted here, the PDFs are saved alongside the original InDesign document, so there’s no danger of the folder not existing.
In some of the modifications posted in the comments, it could indeed happen that the folder doesn’t exist, so then use the general construct demonstrated above.
And, as always, feel free to get in touch if you would like to have some custom scripting done.