So, the following script is a modified version of the script I found here. Its goal is to:
- Export the current page as a PDF using the HQ Print default
- Check for bleed. If there is one, the bleed will be included in export.
- Extract the content of the second text frame (in top to bottom order) it finds on the page
- Extract the first two words of that text, flip their order, add a dash between them, then prepend it to the file name.
- Export the file
As of right now, the only thing I've managed to get working is item #1. For some reason this script won't export bleed no matter what I do, though InDesign's own documentation suggests that what I have in there should work. Also, I've been unable to puzzle out the correct way to handle items 3 and 4; I tried to modify the GetDate function to handle this, but it didn't work (as you can see from the commented out lines).
So scripting gurus of StackExchange, what am I doing wrong? Any and all help will be much appreciated. Thanks!
*Note-- I don't actually need the date appended to the filename; I was just using the GetDate function as a container for the name extraction code, since the function was already there in the code.
var scriptName = "Export current page to PDF - 1.0";
Main();
//===================================== FUNCTIONS ======================================
function Main() {
if (app.documents.length == 0) ErrorExit("Please open a document and try again.", true);
var doc = app.activeDocument;
if (app.activeWindow.constructor.name != "LayoutWindow") ErrorExit("Unable to get page number. Quit story editor.", true);
var page = app.activeWindow.activePage;
with (app.pdfExportPreferences){
pageRange = page.name;
viewPDF = true;
bleedBottom = app.activeDocument.documentPreferences.
documentBleedBottomOffset;
bleedTop = app.activeDocument.documentPreferences.documentBleedTopOffset;
bleedInside = app.activeDocument.documentPreferences.
documentBleedInsideOrLeftOffset;
bleedOutside = app.activeDocument.documentPreferences.
documentBleedOutsideOrRightOffset;
//If any bleed area is greater than zero, then export the bleed.
if(bleedBottom == 0 && bleedTop == 0 && bleedInside == 0 &&
bleedOutside == 0){
useDocumentBleedWithPDF = true;
}
else{
useDocumentBleedWithPDF = false;
}
}
var fileName = doc.name.replace(/\.indd$/, "") + "_" + GetDate() + ".pdf";
var file = new File("~/Desktop/" + fileName);
var myExportPreset = app.pdfExportPresets.item("[High Quality Print]");
alert (myExportPreset);
doc.exportFile(ExportFormat.pdfType, file, false, myExportPreset);
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------
function GetDate() {
//var page = app.activeWindow.activePage;
//var nameFrame = page.textFrames.item(1).contents;
//var employeeName = nameFrame.substr(2)
var date = new Date();
if ((date.getYear() - 100) < 10) {
var year = "0" + new String((date.getYear() - 100));
}
else {
var year = new String((date.getYear() - 100));
}
var dateString = (date.getMonth() + 1) + "-" + date.getDate() + "-" + year + "_" + date.getHours() + "-" + date.getMinutes() + "-" + date.getSeconds();
return dateString;
}