• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Simple script for exportingall pages as PNG with page dimensions in filename

Community Beginner ,
Jan 25, 2021 Jan 25, 2021

Copy link to clipboard

Copied

I'm looking for a script that saves all pages as PNGs with the dimensions in the filename.

All export settings except for the destination can be specified inside the script file.

All i want to do is:

  1. Run the script
  2. Select destination folder
  3. Done

Each files dimensions should appear in the filename, DocumentFilename_[width]x[height]

I realise that I might run into problems if multiple pages have the same dimension.

TOPICS
Import and export , Scripting

Views

1.0K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jan 25, 2021 Jan 25, 2021

Try this where the file name starts with a page number prefix in case the bounds are the same:

 

 

//resolution and anti-aliasing?
var res = 72;
var aa = true;

var pngFolder = Folder.selectDialog("Select the PNG Save folder", ""); 
var doc = app.documents.item(0);
var n = fileName(doc.name);
var nPrefs = app.generalPreferences.pageNumbering;
app.generalPreferences.pageNumbering = PageNumberingOptions.ABSOLUTE;
var dPages = doc.pages;

for (var i = 0; i < dPages.length; i++){
    var pn = dPages
...

Votes

Translate

Translate
Advisor ,
Jan 25, 2021 Jan 25, 2021

Copy link to clipboard

Copied

Hello,

re; "I'm looking for a script that saves all pages as PNGs with the dimensions in the filename."

Are you wanting to export each Page itself as a PNG file? not the page items for each page correct?

 

re; "Each files dimensions should appear in the filename, DocumentFilename_[width]x[height]

I realise that I might run into problems if multiple pages have the same dimension."

Should you inclue the page# in the file naming to prrevent the files from over writing each other?

 

Regards,

Mike

 

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 25, 2021 Jan 25, 2021

Copy link to clipboard

Copied

– Yes i want to export full pages no page items.

– I don't think that will be a problem. I guess will be overwritten with the last page with the same dimension.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 25, 2021 Jan 25, 2021

Copy link to clipboard

Copied

Try this where the file name starts with a page number prefix in case the bounds are the same:

 

 

//resolution and anti-aliasing?
var res = 72;
var aa = true;

var pngFolder = Folder.selectDialog("Select the PNG Save folder", ""); 
var doc = app.documents.item(0);
var n = fileName(doc.name);
var nPrefs = app.generalPreferences.pageNumbering;
app.generalPreferences.pageNumbering = PageNumberingOptions.ABSOLUTE;
var dPages = doc.pages;

for (var i = 0; i < dPages.length; i++){
    var pn = dPages[i].documentOffset + 1;
    var bnds = dPages[i].bounds;
    var expName = exportName(n, pn, bnds);
   
    var thePath = pngFolder + "/" + expName + ".png"
    app.pngExportPreferences.properties = {antiAlias:aa, exportingSpread:false, exportResolution:res, pngExportRange:1785742674, pageString: pn.toString()}
    doc.exportFile(ExportFormat.PNG_FORMAT, File(thePath), false);    
};   
app.generalPreferences.pageNumbering = nPrefs;




/**
* Strip Extension 
*  the file name 
*  value file name with no ext
* 
*/
function fileName(n){
    var na = n.split( "." )
    if ( na.length > 1 ) {
        na.length--;
    }
    na = na.join(".");
    return na
}

/**
* The export file name 
*  document name 
*  page number 
*  page bounds 
*  file name as string 
* 
*/
function exportName(n, pn, b){
    var pre = pn.toString();
    if (pre.length < 2) {
        pre = "0" + pre;
    } 
    var w = b[2]-b[0];
    var h = b[3]-b[1];
    var s = pre + "_" + n + "_" + "[" + w + "]X[" + h + "]";
    return s
}

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 25, 2021 Jan 25, 2021

Copy link to clipboard

Copied

Thanks!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Nov 08, 2023 Nov 08, 2023

Copy link to clipboard

Copied

LATEST
JavaScript for InDesign exports pages using unique names drawn from each page's content. Video tutorial is Windows. Script works the same both macOS and Windows. This is an update to an earlier video: https://youtu.be/3ldKqt1p14k When I made the first video, users contacted me with ideas for more

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines