Copy link to clipboard
Copied
Hello,
I found a very useful script to save covers as JPEG, with a fixed width, whatever is the original size :
//the export pixel width var targetWidthPixels = 600; var doc = app.activeDocument; with(doc.viewPreferences){ horizontalMeasurementUnits = MeasurementUnits.INCHES; verticalMeasurementUnits = MeasurementUnits.INCHES; } //get the page width in inches var pw=doc.documentPreferences.pageWidth; //calulate the resolution needed to export the jpeg as 1500px wide //if the page is 8.5" x 11", the output pixel dimensions will be 600px x 776px var resout= targetWidthPixels/pw; //the active page var pg=app.activeWindow.activePage.name; //set the res preference and page range with(app.jpegExportPreferences){ exportResolution = resout; pageString = pg; antiAlias = true; embedColorProfile = true; jpegColorSpace = JpegColorSpaceEnum.RGB; //add other properties as needed } //export the JPEG doc.exportFile( ExportFormat.jpg, File(Folder.desktop + "/ExportJPG.jpg"), false );
My question is : how to put this file in a specific folder (/Users/toto/Desktop/TEST MTP/OUT site) with a specific name wich is the 14 first characters of every Indesign file name (9782340-046337_COUV_2022_02_24.indd becomes 9782340-046337.jpg)
Thanks for your Help
You have to modify this part:
File(Folder.desktop + "/ExportJPG.jpg")
"Folder.desktop" would be your "/Users/toto/Desktop/TEST MTP/OUT site"
"/ExportJPG.jpg" would be something like that:
'/' + doc.name.substring(0,13) + '.jpg'
But I'm not JS guy so someone else needs to check and confirm.
File("/Users/toto/Desktop/TEST MTP/OUT site/" + doc.name.substring(0,13) + ".jpg")
I think:
var pg = 3;
should work - or "3".
Copy link to clipboard
Copied
No, it's just that the script does not launch when I play it on the PC. Just Nothing…
By @Stephane27925305ylf8
Could you please post your latest code again - using:
Copy link to clipboard
Copied
Here it is, with a more simple target adress on the PC…
Copy link to clipboard
Copied
//the export pixel width
var targetWidthPixels = 1000;
var doc = app.activeDocument;
with(doc.viewPreferences){
horizontalMeasurementUnits = MeasurementUnits.INCHES;
verticalMeasurementUnits = MeasurementUnits.INCHES;
}
//get the page width in inches
var pw=doc.documentPreferences.pageWidth;
//calulate the resolution needed to export the jpeg as 1500px wide
//if the page is 8.5" x 11", the output pixel dimensions will be 600px x 776px
var resout= targetWidthPixels/pw;
//the active page
var pg="Print:3";
//set the res preference and page range
with(app.jpegExportPreferences){
exportResolution = resout;
pageString = pg;
antiAlias = true;
embedColorProfile = true;
jpegColorSpace = JpegColorSpaceEnum.RGB;
//add other properties as needed
}
//export the JPEG
doc.exportFile(
ExportFormat.jpg,
File("C:\Users\louis\Documents\TEST_MTP\OUT" + doc.name.substring(0,13) + ".jpg"),
false
);
Copy link to clipboard
Copied
Copy link to clipboard
Copied
JavaScript is case sensitive, so it rather should be:
ExportFormat.JPG
in the exportFile()?
https://www.indesignjs.de/extendscriptAPI/indesign-latest/#ExportFormat.html
But, it's the same in your original code - that was working on Mac?
Copy link to clipboard
Copied
OK thanks, I will try it although it works like that on MacOS 🙂
Copy link to clipboard
Copied
@Stephane27925305ylf8 wrote://export the JPEG doc.exportFile( ExportFormat.jpg, File("C:\Users\louis\Documents\TEST_MTP\OUT" + doc.name.substring(0,13) + ".jpg"), false );
I think you want forward slashes for the file path—try this:
doc.exportFile(ExportFormat.jpg, File("C:/Users/louis/Documents/TEST_MTP/OUT/" + doc.name.replace(RegExp('()?\.[^\.]+$'), '') + ".jpg"), false);
//returns C:/Users/louis/Documents/TEST_MTP/OUT/MyExportDocument.jpg for a doc named MyExportDocument.indd
Copy link to clipboard
Copied
Copy link to clipboard
Copied
This is what I get for VS Code and it fails on OSX:
$.writeln("C:\Users\louis\Documents\TEST_MTP\OUT" + doc.name.replace(RegExp('()?\.[^\.]+$'), '') + ".jpg")
//returns C:UserslouisDocumentsTEST_MTPOUTMyExportDocument.jpg
Or if I get the ID document’s .filePath the file path string returns as this
$.writeln(doc.filePath)
//returns ~/~FISHERCAT%20ONGOING/CLOUD%20ONGOING%20/Dropbox/SCRIPTING
Copy link to clipboard
Copied
Copy link to clipboard
Copied
I think ExtendScript wants the folder path in URI notation so it is cross platform:
https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Folder.html
Copy link to clipboard
Copied
Yes! Thanks very much, it works! 🙂
But… Instead of having the specific page as requested here in the script :
//the active page
var pg="Print:3";
It exports all the pages of the document :-((
I make my tests with exactly the same Indd document on Mac and on PC.
Copy link to clipboard
Copied
You’ll need to set range rather than all in the jpegExportPreferences by adding jpegExportRange
//set the res preference and page range
with(app.jpegExportPreferences){
exportResolution = resout;
jpegExportRange = ExportRangeOrAllPages.EXPORT_RANGE;
pageString = pg;
antiAlias = true;
embedColorProfile = true;
jpegColorSpace = JpegColorSpaceEnum.RGB;
//add other properties as needed
}
If that doesn’t work you might need to get the page string:
var pg=app.activeWindow.activePage.name;
Copy link to clipboard
Copied
Try running this:
var f = Folder.selectDialog("Select a Destination Folder");
if(f != null){
alert(f)
}
I get:
Copy link to clipboard
Copied
Hi @Stephane27925305ylf8 , you could also choose the destination folder from the script, something like this"
//Choose a folder
var f = Folder.selectDialog("Select a Destination Folder");
if(f != null){
app.scriptPreferences.measurementUnit = MeasurementUnits.INCHES;
//the export pixel width
var targetWidthPixels = 600;
var doc = app.activeDocument;
//use the document’s name for export
var n = doc.name.replace(RegExp('()?\.[^\.]+$'), '');
//get the page width in inches
var pw=doc.documentPreferences.pageWidth;
//calulate the resolution needed to export the jpeg as 1500px wide
//if the page is 8.5" x 11", the output pixel dimensions will be 600px x 776px
var resout= targetWidthPixels/pw;
//the active page
var pg=app.activeWindow.activePage.name;
//set the res preference and page range
with(app.jpegExportPreferences){
exportResolution = resout;
pageString = pg;
antiAlias = true;
embedColorProfile = true;
jpegColorSpace = JpegColorSpaceEnum.RGB;
//add other properties as needed
}
//export the JPEG
doc.exportFile(ExportFormat.jpg, File(f + "/" + n + ".jpeg"), false);
app.scriptPreferences.measurementUnit = AutoEnum.AUTO_VALUE;
}
Copy link to clipboard
Copied
Thank you Rob, I'll try that (even if my goal is always the same place on the computer)
Find more inspiration, events, and resources on the new Adobe Community
Explore Now