Copy link to clipboard
Copied
I've gotten permission from Dave Saunders to ask someone here to help modify a script he wrote way back when.
The script is posted at:
http://pdsassoc.com/downloads/PDFimportCropPref.jsx.zip
The purpose of the script is to change the Crop options of an already placed PDF (includes AI and INDD) file.
The script was written in 2006 for CS2 and so it doesn't work in today's environment.
I'm posting a copy of the text in the hope it doesn't get garbled.
//DESCRIPTION: Allows user to change PDF-import cropping preference
/*
©Copyright 2006 PDS Associates
This script must not be distributed without first obtaining written permission of:
Dave Saunders, proprietor
PDS Associates
P.O. Box 127
Allenhurst, NJ 07711-0127
e-mail: davesaunders@pdsassoc.com
*/
// Destroy any existing dialogs
if (app.dialogs.length > 0) app.dialogs.everyItem().destroy();
interactWithAll();
curSetting = app.pdfPlacePreferences.pdfCrop;
userChooses = askUser(curSetting);
app.pdfPlacePreferences.pdfCrop = userChooses
// +++++++ Functions Start Here +++++++++++++++++++++++
function interactWithAll() {
if (app.version == 3) {
app.userInteractionLevel = UserInteractionLevels.interactWithAll;
} else {
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;
}
}
function askUser(curValue){
var cropChoices = ["Art", "Bleed", "Content", "Media", "PDF", "Trim"];
var cropValues = [1131573313, 1131573314, 1131573315, 1131573325, 1131573328, 1131573332];
cv = -1;
for (var j = cropValues.length – 1; j >= 0; j–) {
if (curValue == cropValues
cv = j;
continue
}
}
if (cv == -1) errorExit(“Current value of crop preference not recognized”);
with (app.dialogs.add({name:”Place PDF Crop Preference”})) {
with (dialogColumns.add()) {
with (dialogRows.add()) {
staticTexts.add({staticLabel:”Choose preference:”});
uchoose = dropdowns.add({stringList:cropChoices, selectedIndex:cv})
}
}
app.activate();
if (!show()) {
// User canceled;
destroy();
exit()
} else {
value = cropValues[uchoose.selectedIndex];
destroy();
}
return value
}
}
function errorExit(message) {
if (arguments.length > 0) {
if (app.version != 3) { beep() } // CS2 includes beep() function.
alert(message);
}
exit(); // CS exits with a beep; CS2 exits silently.
}
If you are interested in this challenge, your modified script will be mentioned at InDesignSecrets.com where we can link to your download page as well as extoll the brilliance of your scripting abilities. Sorry, no money, just glory.
Send me a message at Sandee at mac dot com if you want to tackle the script.
Thanks
Copy link to clipboard
Copied
Okay I want glory
Let's try to make it short:
//====================================================================
// PDFImportCropPref Reloaded
// (should work in ID CS/CS2/CS3/CS4/CS5/CS6/CC)
//====================================================================
(function(o,a,z,r,i,x,t,k)
{
for(k in o) o.hasOwnProperty(k) &&
(a['_'+z]=t=+o
) && (a[z++]=k.substr(5).replace(r,' ')) &&
(i||(x==t&&(i=z)));
(((k='userInteractionLevel')in(o=app))?o:o.scriptPreferences)
= +UserInteractionLevels.interactWithAll; (t=o.dialogs).length && t.everyItem().destroy();
r=(t=t.add({name:"Place PDF Crop Preference"}))
.dialogColumns.add().dialogRows.add()
.staticTexts.add({staticLabel:"Choose preference: "})
.parent.dropdowns.add({stringList:a,selectedIndex:i-1});
o.activate();
t.show() && (o.pdfPlacePreferences.pdfCrop=a['_'+r.selectedIndex]);
})(PDFCrop,[],0,/_/g,0,+app.pdfPlacePreferences.pdfCrop);
@+
Marc
Copy link to clipboard
Copied
Hi,
... end of competition ...
Jarek
Copy link to clipboard
Copied
After CS4 there are changes in "Pdfcrop" enums list.
Instead of "CROP_CONTENT" new enums were introduced "CROP_CONTENT_ALL_LAYERS" and "CROP_CONTENT_VISIBLE_LAYERS". hence this script does not work in current versions of InDesign.
if you replace two lines:
var cropChoices = ["Art", "Bleed", "Content", "Media", "PDF", "Trim"];
var cropValues = [1131573313, 1131573314, 1131573315, 1131573325, 1131573328, 1131573332];
With these lines:
var cropChoices = ["Art", "Bleed", "ContentAllLayers","ContentVisibleLayers", "Media", "PDF", "Trim"];
var cropValues = [1131573313, 1131573314, 1131561324,1131566703, 1131573325, 1131573328, 1131573332];
It will be compatible with CS5 and later versions of InDesign.
Or, You can use @Marc script , that is more generic.
Copy link to clipboard
Copied
Thanks Marc and Sumgarg for helping Sandee. I've been in hospital for three weeks and am only now able to starting thinking again.
Dave
Copy link to clipboard
Copied
I wish you a quick & speedy recovery, Dave!
I’ve learned a lot from your posts, site and blog. Without people like you, I‘d never become a scripter. Thank you a lot!
Kasyan