Skip to main content
dublove
Legend
Jun 18, 2025 10:20 AM UTC
Answered

Why "app.pdfExportPreferences.pageRange = PageRange.allPages;" didn't work the 1st time?

I tried, with a script to export all pages.
However, when I manually export a single page (say page 6) from File>>Export>>.
Then, I run the script and it still exports page 6.
The 2nd time I run the script, it exports all pages.

Is there a cache? How do I clear it?

 

Seems like someone on the forum mentioned this, The problem does not seem to have been resolved.

https://community.adobe.com/t5/indesign-discussions/problems-with-pagerange-allpages-reliability/td-p/3536073

The next sentence is the same. 2nd entry into force.

app.pdfExportPreferences.pageRange = PageRange.ALL_PAGES;

 

try {
    if (myDialog.show() == 1) {
        var myPDFExportPreset = app.pdfExportPresets.item(myDropdown.selection.text);
        myDocument.exportFile(ExportFormat.PDF_TYPE, myPDFFile, false, myPDFExportPreset);
        app.pdfExportPreferences.pageRange = PageRange.allPages;
    } else {
        alert('Export canceled');
    }
}
catch (e) { alert("is OPEN……") }

 

m1b
m1bCorrect answer
Community Expert
Jun 18, 2025 11:54 AM UTC

It should be formed like this:

app.pdfExportPreferences.properties = {
    pageRange: PageRange.ALL_PAGES,
    exportAsSinglePages: true,
    viewPDF: false,
};

 

which is the same as this:

app.pdfExportPreferences.pageRange = PageRange.ALL_PAGES;
app.pdfExportPreferences.exportAsSinglePages = true;
app.pdfExportPreferences.viewPDF = false;

 

4 replies

Community Expert
Jun 18, 2025 10:57 AM UTC

Adding to what @m1b said, the problem is in your code's sequence of lines. When you export page 6 manually you set the page range option. On executing the script after that, the script reads the page range set by the manual export i.e. 6 and hence exports only that page. In the script, after export you set the page range to all, so the next time you export, all pages are exported.

So what you need to do is set page range before exporting

-Manan

Translate
-Manan
m1b
Community Expert
Community Expert
Jun 18, 2025 10:36 AM UTC

Hi @dublove try this please. Add this line:

app.pdfExportPreferences.pageRange = PageRange.ALL_PAGES;

 

It must go BEFORE the exportFile call.

 

Or you can do

app.pdfExportPreferences.pageRange = "2"

 

Or

app.pdfExportPreferences.pageRange = "2,3,14-20"

 

Remember it must go BEFORE the exportFile call.

- Mark

Translate
dublove
dubloveAuthor
Legend
Jun 18, 2025 11:38 AM UTC
@m1b  Thank you
This one of yours, I put it in the 1st sentence of try and it seems to work.
Why is this my next sentence incorrect?
app.pdfExportPreferences.pageRange = { PageRange: ALL_PAGES, exportAsSinglePages: true, viewPDF: false };
Translate
m1b
Community Expert
m1bCommunity ExpertCorrect answer
Community Expert
Jun 18, 2025 11:54 AM UTC

It should be formed like this:

app.pdfExportPreferences.properties = {
    pageRange: PageRange.ALL_PAGES,
    exportAsSinglePages: true,
    viewPDF: false,
};

 

which is the same as this:

app.pdfExportPreferences.pageRange = PageRange.ALL_PAGES;
app.pdfExportPreferences.exportAsSinglePages = true;
app.pdfExportPreferences.viewPDF = false;

 

Translate