Skip to main content
Jedit-inc
Participating Frequently
Dec 8, 2019 1:12 PM UTC
Answered

Export Multiple Page Ranges to seperate PDFs from 1 export

Dear Community,

 

I have been using Indesign since CS2 and I have never came across this particular problem before. I am hoping someone here can help me. I have 7 seperate indesign documents each from a data merge. Each document has close to 300 pages. What I need is very simple but for the life of me I cannot figure out how to do it efficiently. I need to export multiple page ranges for each indesign document and have each range be a seperate pdf. Here's an example of what I mean.

 

Indesign Document:

1-2, 4-5, 7-16, 18-19, 21-30, 32-35, 37-38, 40-49, 51-52, 54-57, 59-74, 76-79, 81-82, 84-85, 87-92

 

I need a way to export so that basically the comma means *NEW PDF*. 

 

The only way I found so far to do this is to manually export the ranges 1 at a time which takes literally hours to go through each id file OR I found 1 plugin this morning that may do it called "extract Pages".

 

https://www.id-extras.com/products/extract-pages/

 

There's got to be an easier way right? I shouldn't have to spend $50 to do this seemingly insanely simple export. 

 

Any ideas guys?

 

Thanks!

 

 

 

rob day
rob dayCorrect answer
Community Expert
Oct 19, 2024 9:44 PM UTC

@rob day Thanks for the reply, I installed the script and ran it, it shows me all the settings to choose from that I need but when I want to generate the PDF it shows me this alert

 


The exportFile method needs a file path, which was not included in the code I pasted from jongware’s first post. Maybe this:

 

makeDialog();
var pp, pglist;

function makeDialog(){
    var theDialog = app.dialogs.add({name:"Choose a Preset", canCancel:true});
    with(theDialog.dialogColumns.add()){
        staticTexts.add({staticLabel:"Export Preset:"});
        staticTexts.add({staticLabel:"Page Range:"});
        
    }
    with(theDialog.dialogColumns.add()){
        pp = dropdowns.add({stringList:app.pdfExportPresets.everyItem().name, selectedIndex:3, minWidth:80});
        pglist = textEditboxes.add({editContents:"", minWidth:350});
    }
    if(theDialog.show() == true){
        pp = app.pdfExportPresets.item(pp.selectedIndex);
        pglist = pglist.editContents.split(',');
        var path = app.activeDocument.fullName.path;
        for (i=0; i<pglist.length; i++){
            app.pdfExportPreferences.pageRange = pglist[i];
            app.activeDocument.exportFile(ExportFormat.PDF_TYPE, File(path+'/pages_'+pglist[i]+'.pdf'), false, pp);
        }
        theDialog.destroy();
	}
}

40 replies

Community Expert
Dec 9, 2019 12:11 PM UTC

Jongware said:

…I checked on my Windows machine and indeed it tries to store the files in the Scripts folder, which is inside a "protected folder" (a Microsoft "feature", so not a bug ...). …

 

Was this the Application folder of your Scripts panel?

Then I'd try to store the script in the User folder of the Scripts panel.

 

Regards,
Uwe Laubender

( ACP )

Translate
Participating Frequently
Mar 2, 2025 11:12 AM UTC

It's a bit late but here is an updated version that opens the pdf export window so you can adjust the settings for your export.


//DESCRIPTION:Export page ranges with single PDF Export Dialog
// Modified on 02-Mar-2025

pglist = prompt('Page list', '');
path = app.activeDocument.fullName.path;
pglist = pglist.split(/,\s*/);

// Ask the user to manually configure the export settings once
var pdfFile = new File(path + '/temp_export.pdf');
app.activeDocument.exportFile(ExportFormat.PDF_TYPE, pdfFile, true); // Opens dialog once
pdfFile.remove(); // Delete temporary file

// Apply the same settings to the rest
for (i = 0; i < pglist.length; i++) {
app.pdfExportPreferences.pageRange = pglist[i];
var finalPdfFile = new File(path + '/pages_' + pglist[i] + '.pdf');
app.activeDocument.exportFile(ExportFormat.PDF_TYPE, finalPdfFile, false); // Uses the same settings
}

Translate
A2D2
Inspiring
Apr 29, 2025 12:03 PM UTC

Thank you for taking the time to revisit this Wael. I agree that a version that opens the export dialogue would be useful. However, I am afraid your script did not work for me with ID CS6 on a 700+ page doc which needed a PDF for each 20 pages. ID crashed and closed without giving an error. I tried this twice. First time: I tried to extract from page 40 onwards in batches of 20. Second time: I started my page list from 1 with no gaps in the sequence.

 

The script by @rob day worked for me very well. I pasted a list in the pop-up box "1-20, 21-40, 41-60..." and PDFs were exported to the working folder of the document. After each PDF is exported it is opened which means a lot of PDFs were opened!

 

Lastly, there is another thread in the community on this topic which has a Github sin-off:

https://community.adobe.com/t5/indesign-discussions/script-export-page-ranges-to-multiple-pdfs-fast-export-workflow/td-p/14849389

 

https://github.com/MoebiusSt/exportPageRangesToPDF.jsx

 

Translate
Jongware
Community Expert
Community Expert
Dec 9, 2019 10:02 AM UTC

(Sorry, didn't mean to leave you hanging. I must be in a different time zone -- my original answer was done right before closing down for the night.)

I've found your bug -- and it's actually toted as a "feature". My Mac had no problems with the script but I get your error on my Windows 'chine as well. Apparently the default location to save in, if no path has been given, is the scripts folder. I didn't notice because my Mac automatically opened the files as they were created and I just glanced at them if the page ranges worked -- I *think* I assumed they were saved in 'the current folder', i.e., the one my test document was in. But InDesign did not do that. After a bit of lateral thinking I checked on my Windows machine and indeed it tries to store the files in the Scripts folder, which is inside a "protected folder" (a Microsoft "feature", so not a bug ...).

Fortuntately, the fix is easy -- just prepend the path of the current file. That leads us to this:

 

//DESCRIPTION:Export page ranges
// A Jongware Script 09-Dec-2019
pglist = prompt ('Page list', '');
exportPreset = '[High Quality Print]';
path = app.activeDocument.fullName.path;
pglist = pglist.split(/,\s*/);
for (i=0; i<pglist.length; i++)
{
	app.pdfExportPreferences.pageRange = pglist[i];
	app.activeDocument.exportFile(ExportFormat.PDF_TYPE, File(path+'/pages_'+pglist[i]+'.pdf'), false, app.pdfExportPresets.item(exportPreset));
}

 

Translate
Jedit-inc
Jedit-incAuthor
Participating Frequently
Dec 9, 2019 11:23 AM UTC

No worries at all. Thank you! This works perfectly! I really appreciate your help! 

Translate
Jongware
Community Expert
Community Expert
Dec 8, 2019 1:37 PM UTC

It's quite contradictory to first say it will cost you hours of your time and then say you "should not have to spend $50" on a plug-in that will save you that much time ...

But – fortunately your task is easy to script! This is all it takes -- copy your page range list and paste it into the prompt that appears, and you'll get your PDFs, named as "pages_1-2.pdf" etc.

//DESCRIPTION:Export page ranges
// A Jongware Script 08-Dec-2019
pglist = prompt ('page list', '');
exportPreset = '[High Quality Print]';
pglist = pglist.split(',');
for (i=0; i<pglist.length; i++)
{
	app.pdfExportPreferences.pageRange = pglist[i];
	app.activeDocument.exportFile(ExportFormat.PDF_TYPE, File('pages_'+pglist[i]+'.pdf'), false, app.pdfExportPresets.item(exportPreset));
}

 

Translate
BobLevine
Community Expert
Community Expert
Dec 8, 2019 1:39 PM UTC

Agreed. I despise that attitude. $50 to save hours of work?

Seems like a bargain to me.

Translate