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:
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.
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
...
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
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.
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
}
Copy link to clipboard
Copied
Thanks!
Copy link to clipboard
Copied