Export InDesign document to Image File
Copy link to clipboard
Copied
Hi,
I confidently exported a 10-page InDesign document to JPG, but I assertively need to exclude the master page from the export. Please guide me on this.
var doc = app.activeDocument;
for (var i = 0; i < doc.pages.length; i++) {
var currentPage = doc.pages[i];
app.jpegExportPreferences.exportResolution = 300; // Change resolution if needed
var exportFile = new File("/C/Users/ADMIN/Documents//Page_" + (i + 1) + ".jpg");
currentPage.exportFile(ExportFormat.JPG, exportFile);
}
Copy link to clipboard
Copied
As i understand master page won't be executed using the code you shared.
Copy link to clipboard
Copied
The exported InDesign document shows an empty image file. Kindly find the attached screenshot.
Copy link to clipboard
Copied
According to https://www.indesignjs.de/extendscriptAPI/indesign-latest/#about.html - you can't call ExportFile on a Page??
VB have Export - but it can't be called on a Page object ?
Is it from the latest version - 2024 / v19? Not upgraded yet.
Copy link to clipboard
Copied
Hi
Sorry for the inconvenience, by using the below-given script I have achieved the export option but the blank pages appear in the export file path. I'm using the InDesign 2022 version 17.1
var doc = app.activeDocument;
for (var i = 0; i < doc.pages.length; i++) {
var currentPage = doc.pages[i];
app.jpegExportPreferences.exportResolution = 300; // Change resolution if needed
var exportFile = new File("/C/Users/ADMIN/Documents/Page_" + (i + 1) + ".jpg"); // Change path and file format if needed
currentPage.exportFile(ExportFormat.JPG, exportFile);
}
Copy link to clipboard
Copied
A page has no exportFile method, why your script fails to run.
Try the following approach:
var doc = app.activeDocument;
for(i=0; i<doc.pages.length; i++) {
app.jpegExportPreferences.properties = {
exportResolution: 300,
jpegExportRange: ExportRangeOrAllPages.exportRange,
pageString: String(i+1)
};
doc.exportFile(ExportFormat.JPG, File("/your/output/path/" + (i+1) + ".jpg"));
}
Don't forget to update the output path as desired. The script should also exclude master pages from export.
Robotic Process Automation in Desktop Publishing (Book): https://doi.org/10.1007/978-3-658-39375-5
Copy link to clipboard
Copied
A page has no exportFile method, why your script fails to run.
[...]
By GNDGN
Yes, already mentioned, but for some strange reason - OP's script is working for him??
Copy link to clipboard
Copied
I was about to post the same as @GNDGN —the page object doesn’t have an exportFile() method so when I run @MonishaRajendran ’s last script I get this expected error:
Copy link to clipboard
Copied
The doc.pages collection contains just document pages, not master pages, so it's not clear what Monisha has actually done.
Copy link to clipboard
Copied
Monisha and GNDGN are using some undocumented function for exporting pages?
Copy link to clipboard
Copied
GNDGN sets the page (range) to be exported, which is the standard method. Same goes for PDF.
Copy link to clipboard
Copied
![](/skins/images/1A2984DC5E3889F4435E998DD71294F3/responsive_peak/images/icon_anonymous_message.png)
![](/skins/images/1A2984DC5E3889F4435E998DD71294F3/responsive_peak/images/icon_anonymous_message.png)