Skip to main content
dublove
Legend
June 18, 2025
Answered

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

  • June 18, 2025
  • 2 replies
  • 261 views

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……") }

 

Correct answer m1b

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;

 

2 replies

Community Expert
June 18, 2025

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

-Manan
m1b
Community Expert
Community Expert
June 18, 2025

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

dublove
dubloveAuthor
Legend
June 18, 2025
@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 };
m1b
Community Expert
m1bCommunity ExpertCorrect answer
Community Expert
June 18, 2025

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;