0

So, the following script is a modified version of the script I found here. Its goal is to:

  1. Export the current page as a PDF using the HQ Print default
  2. Check for bleed. If there is one, the bleed will be included in export.
  3. Extract the content of the second text frame (in top to bottom order) it finds on the page
  4. Extract the first two words of that text, flip their order, add a dash between them, then prepend it to the file name.
  5. 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;  
}  
1

Regarding the bleed, you are almost there. You have inverted the logic in the bleed test, and you should not be using the preset, since you are already setting the preferences in your with pdfExportPreferences block.

Perhaps if you want to use a preset, then you should load the preset before the with block, but I haven't tested that.

So:

//If any bleed area is greater than zero, then export the bleed.
if(bleedBottom == 0 && bleedTop == 0 && bleedInside == 0 &&
    bleedOutside == 0){

Should be:

 if(bleedBottom != 0 && bleedTop != 0 && bleedInside != 0 &&
        bleedOutside != 0){

And:

var myExportPreset = app.pdfExportPresets.item("[High Quality Print]");
alert (myExportPreset);
doc.exportFile(ExportFormat.pdfType, file, false, myExportPreset);

Should be:

doc.exportFile(ExportFormat.pdfType, file, false);
  • 1
    fun fact: the scripting panel in ID will follow folder shortcuts. Drop a link in the User scripts folder to any other folder. – Yorik Mar 20 '15 at 16:15
  • What does that mean in terms of the script itself? Sorry, I don't really know any scripting; what I managed above was the result of several hours and research and frustration. – ajw-art Mar 20 '15 at 16:17
  • Oh, that is neat! And very useful actually, as I'd like to keep this script on the server for my entire team to use. – ajw-art Mar 20 '15 at 16:18
  • 1
    Nothing. I just have a "research" folder on my desktop which I added a link to. I like to have my scripts etc in an easier location for access and backups. This way they don't get buried in the programs folder. – Yorik Mar 20 '15 at 16:19
  • Now he last the settings from the "[High Quality Print]" preset as intended. – Bruno Dec 19 '17 at 6:41
0

You need to duplicate the "[High Quality Print]" preset and make any changes as unlike the pageRange preference, the bleed settings will be over-ridden by the ExportPreset. You can bin your duplicated preset when you're done:

var myExportPreset = app.pdfExportPresets.item("[High Quality Print]").duplicate();
myExportPreset.useDocumentBleedWithPDF = true;

doc.exportFile(ExportFormat.PDF_TYPE, myFile, false, myExportPreset );
myExportPreset.remove();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.