Mobile app version of vmapp.org
Login or Join
Welton168

: Script won't output bleed on PDF export, and stuck on other portion of script So, the following script is a modified version of the script I found here. Its goal is to: Export the current

@Welton168

Posted in: #AdobeIndesign #IndesignScripting

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;
}

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Welton168

2 Comments

Sorted by latest first Latest Oldest Best

 

@Megan533

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();

10% popularity Vote Up Vote Down


 

@Sherry646

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);

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme