Copy link to clipboard
Copied
Hi all,
I have a specific 'Package For Print' script, that needs a small modification, and and I was hoping someone could help me.
Essentially, I need to OMIT 'Include PDF' option when packaging, since this makes things a bit wonky on my script (see below).
Let me know if you need to see the script, and I'll post it.
Thank you.
1 Correct answer
Hi
Parham took my advice and hired me and I got to the route of the problem
The packageForPrint method has changed for 2014. it now has a couple of extra variables that aren't in the previous versions.
The extra one being include pdf (which at least on Parham's system was set as true) and include idml file.
When these values weren't the pdf was being included in a way that messed things up.
The fix was simple, it just took a little bit of time to get to the route of the problem.
I think it's about ti
...Copy link to clipboard
Copied
Moved to the scripting forum...
Copy link to clipboard
Copied
Send the script
Copy link to clipboard
Copied
Here you go, and thank you. I know notes are also included in it. Sorry about this.
//Package the active document and setup the dockets folder structure.
//The active document shouldn't have been saved (has no name), so provide a name
//taken from the first and only link. After creating the dockets folder structure,
//close and delete the original file and open the file in the docket's originals
//folder.
#target InDesign
//Constants
const PROOF_PREFIX = 'Proof_';
const OUTPUT_SUFFIX = ' Folder';
const ORIGINALS_FOLDER = 'Originals';
const PRINT_FOLDER = 'Print';
const DIGITAL_PROOF_FOLDER = 'Digital Proof';
const CLIENT_FOLDER = 'Client Provided Files';
const DEFAULT_MAC_DOCKETS = '/Users/parham/Desktop';
const PDF_PROFILE = 'Linx_Proof'
function Err() {}
//Use a more user-friendly version than throwing an error.
Err.FatalError = function (msg) {
alert(msg, 'Fatal Error', true);
exit();
};
function makeShowUI(runtime) {
var doc = runtime.doc;
var window = (function () {
var windowDef = "Window {\
type: 'dialog', \
properties: { \
resizeable: false, \
closeButton: true, \
maximizeButton: false, \
minimizeButton: false \
}, \
text: 'Dockets Package', \
orientation: 'column', \
}";
var w = new Window(windowDef);
//Folder name
w.add("StaticText { text:'New Folder Name', alignment: 'left' }");
var defaultName = doc.name;
if (defaultName.slice(-5) == '.indd') {
var origlength = defaultName.length;
defaultName = defaultName.substr(0, origlength - 5);
}
w.folderText = w.add("EditText { alignment: 'left', characters: 30, justify: 'left', " +
"text:'" + defaultName + OUTPUT_SUFFIX + "'}");
//Destination dir
w.add("StaticText { text:'Save To', alignment: 'left' }");
var dirGroup = w.add("Group { orientation: 'row', alignment: 'fill' }");
w.dirText = dirGroup.add("EditText { characters: 30, justify: 'left', " +
"text:'" + DEFAULT_MAC_DOCKETS + "'}");
w.dirBrowseBtn = dirGroup.add("Button { text: 'Browse...' }");
w.dirBrowseBtn.textBox = w.dirText;
//Package Options
w.options = w.add("Panel { orientation: 'column', alignment: 'fill', \
text: 'Package Options', alignChildren: 'left'}");
w.options.fonts = w.options.add("Checkbox { text: 'Copy Fonts' }");
w.options.links = w.options.add("Checkbox { text: 'Copy Linked Graphics' }");
w.options.profiles = w.options.add("Checkbox { text: 'Copy Color Profiles' }");
w.options.update = w.options.add("Checkbox { text: 'Update Graphic Links In Package' }");
w.options.hiddenContent = w.options.add("Checkbox { text: 'Include Fonts and Links From Hidden and Non-Printing Content' }");
w.options.ignore = w.options.add("Checkbox { text: 'Ignore Preflight Errors' }");
w.options.report = w.options.add("Checkbox { text: 'Create Report' }");
w.options.fonts.value = true;
w.options.links.value = true;
w.options.profiles.value = true;
w.options.update.value = true;
w.options.hiddenContent.value = true;
w.options.ignore.value = true; //Parham's request for true
w.options.report.value = false; //Saeed's request for false (no instructions)
//Digital Proof
w.proof = w.add("Panel { orientation: 'column', alignment: 'fill', \
text: 'Digital Proof', alignChildren: 'left'}");
w.proof.make = w.proof.add("Checkbox { text: 'Make PDF Proof' }");
w.proof.viewAfter = w.proof.add("Checkbox { text: 'View PDF' }");
w.proof.make.value = false;
w.proof.viewAfter.value = false;
//OK / Cancel
var buttonDef = "Group { orientation: 'row', alignment: 'right', alignChildren: 'right' }";
w.bg = w.add(buttonDef);
var okDef = "Button { text: 'OK', alignment: 'right' }";
var cancelDef = "Button { text: 'Cancel', alignment: ['right', 'center'] }";
w.okBtn = w.bg.add(okDef);
w.cancelBtn = w.bg.add(cancelDef);
return w;
})();
runtime.window = window;
window.dirBrowseBtn.onClick = (function () {
var result = Folder.selectDialog('Choose destination directory');
if (null !== result) {
//Replace string with selected path
this.textBox.text = result.fullName;
}
});
return window.show();
}
function deleteFolder(folder) {
if (!folder.exists) {
return;
}
var children = folder.getFiles();
for (var i = 0, im = children.length; i < im; i++) {
if (children instanceof Folder) {
deleteFolder(children);
} else {
children.remove();
}
}
folder.remove();
}
//Main path
try {
var a = app.activeDocument;
} catch (e) {
Err.FatalError("No document open");
}
var runtime = {};
var doc = app.activeDocument;
runtime.doc = doc;
if (doc.saved) {
//Document has already been saved (already has a name), so stop.
Err.FatalError("Document has already been saved");
}
//Ensure at least one link, since multipaged PDFs end up as more than 1 link.
if (doc.links.length < 1) {
Err.FatalError("Document has " + doc.links.length + " links.");
}
//Save the existing file in a temporary place, same dir as first link.
//Take the name from the first link
var link = doc.links.firstItem();
var defaultName = link.name;
if (defaultName.slice(-4) == '.pdf') {
var origlength = defaultName.length;
defaultName = defaultName.substr(0, origlength - 4);
} else {
//Placed item is not a pdf, as per Parham's request, don't warn about it.
//Just take the filename best guess and go with it.
// if (confirm('Linked item is not a PDF. Package anyways?',
// true, 'Package non-PDF')) {
//break on the last '.'
var lastIndex = defaultName.lastIndexOf('.');
if (lastIndex > -1) {
defaultName = defaultName.substr(0, lastIndex);
} else {
defaultName = defaultName;
}
// } else {
// alert('Did not package.');
// exit();
// }
}
//filePath should be a File, but is actually a string, so make a file.
var linkFile = new File(link.filePath);
var origFile = new File(linkFile.path + '/' + defaultName + '.indd');
if (origFile.exists) {
//Folder already exists, get user to confirm
if (confirm("File " + defaultName + '.indd already exists. Replace?',
true, 'Replace File')) {
//Erase the temp file
origFile.remove();
} else {
alert('Did not overwrite existing files, did not package.');
exit();
}
}
doc.save(origFile);
if (2 == makeShowUI(runtime)) {
//User pressed cancel
exit();
}
//Main code, do the packaging and make the directories.
//But first check for existing folder.
var folderName = runtime.window.folderText.text;
var destinationPath = runtime.window.dirText.text;
if (destinationPath.slice(-1) == '/') {
var newFolderPath = destinationPath + folderName;
} else {
var newFolderPath = destinationPath + '/' + folderName;
}
var outputRoot = new Folder(newFolderPath);
if (outputRoot instanceof Folder && outputRoot.exists) {
//Folder already exists, get user to confirm
if (confirm('Dockets folder ' + folderName + ' already exists. Replace?',
true, 'Replace Folder')) {
//Erase the destination directory
//Get all contained files + folders, then delete them.
deleteFolder(outputRoot);
} else {
alert('Did not overwrite existing files.');
exit();
}
} else if (outputRoot instanceof File) {
//Destination folder exists as a file, fail.
Err.FatalError('File named ' + folderName + ' already exists, cannot make folder.');
}
//Destination doesn't exist, create it.
if (!outputRoot.create()) {
Err.FatalError('Error creating folder ' + folderName);
}
//We have an empty directory, now do the packaging and everything else.
var printFolder = new Folder(newFolderPath);
printFolder.changePath(PRINT_FOLDER);
if (!printFolder.create()) {
Err.FatalError('Error creating Print folder.');
}
var digitalProofFolder = new Folder(newFolderPath);
digitalProofFolder.changePath(DIGITAL_PROOF_FOLDER);
if (!digitalProofFolder.create()) {
Err.FatalError('Error creating Digital Proof folder.');
}
var clientFolder = new Folder(newFolderPath);
clientFolder.changePath(CLIENT_FOLDER);
if (!clientFolder.create()) {
Err.FatalError('Error creating Client folder.');
}
var originalsFolder = new Folder(newFolderPath);
originalsFolder.changePath(ORIGINALS_FOLDER);
if (!originalsFolder.create()) {
Err.FatalError('Error creating Originals folder.');
}
//Do the package
var f = runtime.window.options;
if (doc.packageForPrint(originalsFolder, f.fonts.value, f.links.value, f.profiles.value, f.update.value, f.hiddenContent.value, f.ignore.value, f.report.value, false, true)) {
} else {
Err.FatalError('Failed to package.');
}
//Do the PDF proof
if (runtime.window.proof.make.value) {
var proofname = PROOF_PREFIX + doc.name;
if (proofname.slice(-5) == '.indd') {
var origlength = proofname.length;
proofname = proofname.substr(0, origlength - 5);
}
proofname = proofname + '.pdf';
var proofFile = new File(digitalProofFolder.fullName + '/' + proofname);
if (proofFile.exists) {
Err.FatalError('Digital proof already exists.');
} else {
var exportProfile = app.pdfExportPresets.itemByName(PDF_PROFILE);
//We get an object even if the profile doesn't exist, have to check isValid
if (!exportProfile.isValid) {
Err.FatalError('PDF profile ' + PDF_PROFILE + " doesn't exist, digital proof not created.");
}
//Explicitly set to export all pages.
app.pdfExportPreferences.pageRange = PageRange.ALL_PAGES;
//Set view preference
app.pdfExportPreferences.viewPDF = runtime.window.proof.viewAfter.value;
doc.exportFile(ExportFormat.PDF_TYPE, proofFile, false, exportProfile);
}
}
//Open the Originals folder .indd, close the current file and delete it.
var newFile = new File(originalsFolder.fullName + '/' + doc.name);
if (!app.open(newFile)) {
Err.FatalError("Failed to open packaged .indd");
}
doc.close();
origFile.remove();
Copy link to clipboard
Copied
The script you sent has a different interface to the one you sent a screenshot of
Send the correct script (not talking about the color!)
Copy link to clipboard
Copied
Thanks Trevor. I only sent the screen shot to show what box should be
unchecked when I run my own script. Essentially I want to avoid InDesign
making a print PDF when I use the script. That would solve my problem.
Parham Tavakoli
LinxPrint.com | 1930 Powell St. Vancouver, BC, V5L 1J3 | t: 604.254.5469
| f: 604.254.5410 | e: parham@linxprint.com | twitter: @linxprint
Copy link to clipboard
Copied
Hi Parham
After the lines
//Digital Proof
w.proof = w.add("Panel { orientation: 'column', alignment: 'fill', \
text: 'Digital Proof', alignChildren: 'left'}");
w.proof.make = w.proof.add("Checkbox { text: 'Make PDF Proof' }");
w.proof.viewAfter = w.proof.add("Checkbox { text: 'View PDF' }");
add the line
w.proof.visible = false;
Just search the script for the phrase View PDF
It will do the trick
Trevor
@Peter
If you can use your magic powers to erase Parham's personal details you'll be doing him a big favor and saving him a bunch of SPAM
Regards
Trevor
Copy link to clipboard
Copied
Thanks for the help so far Trevor. Unfortunately the pesky print PDF is still inside the 'Originals' folder.
Basically, once I run the script, it is supposed to create a folder on my desktop, with 4 sub-folders in it (Screen1) attached.
It is then supposed to place all relevant links inside a sub-folder in the 'Originals' folder, and have the Indsign file grab the relevant links from that 'Links' folder (Screen 2).
This is what it used to do prior to 2014 upgrade. Now, it creates that print PDF inside the 'Originals' folder, and Indesign links to that file instead of the correct one in the 'Links' folder. This can cause an issue for me since that particular print PDF is not always high resolution (depending on my PDF settings). Now I realise I could manually delete the 'bad file' after the folder is created, but then Indesign complains that the needed links are missing, and one has to manually point to the correct links etc.
Being in a high volume print environment, I'm sure you can imagine this is not ideal, specially since we had a smooth operation prior to this upgrade.
Once again, I appreciate all the help.
Copy link to clipboard
Copied
Hi Parham
I'm sorry I'm too busy to do this one for free now. If you want me to fix it up you can sent me a mail to trevor at creative-scripts dot com for a quote.
I'll post your original script in a formatted form to make it easier for other people to look at it.
Regards
Trevor
//Package the active document and setup the dockets folder structure.
//The active document shouldn't have been saved (has no name), so provide a name
//taken from the first and only link. After creating the dockets folder structure,
//close and delete the original file and open the file in the docket's originals
//folder.
#target InDesign
//Constants
const PROOF_PREFIX = 'Proof_';
const OUTPUT_SUFFIX = ' Folder';
const ORIGINALS_FOLDER = 'Originals';
const PRINT_FOLDER = 'Print';
const DIGITAL_PROOF_FOLDER = 'Digital Proof';
const CLIENT_FOLDER = 'Client Provided Files';
const DEFAULT_MAC_DOCKETS = '/Users/parham/Desktop';
const PDF_PROFILE = 'Linx_Proof'
function Err() {}
//Use a more user-friendly version than throwing an error.
Err.FatalError = function (msg) {
alert(msg, 'Fatal Error', true);
exit();
};
function makeShowUI(runtime) {
var doc = runtime.doc;
var window = (function () {
var windowDef = "Window {\
type: 'dialog', \
properties: { \
resizeable: false, \
closeButton: true, \
maximizeButton: false, \
minimizeButton: false \
}, \
text: 'Dockets Package', \
orientation: 'column', \
}";
var w = new Window(windowDef);
//Folder name
w.add("StaticText { text:'New Folder Name', alignment: 'left' }");
var defaultName = doc.name;
if (defaultName.slice(-5) == '.indd') {
var origlength = defaultName.length;
defaultName = defaultName.substr(0, origlength - 5);
}
w.folderText = w.add("EditText { alignment: 'left', characters: 30, justify: 'left', " +
"text:'" + defaultName + OUTPUT_SUFFIX + "'}");
//Destination dir
w.add("StaticText { text:'Save To', alignment: 'left' }");
var dirGroup = w.add("Group { orientation: 'row', alignment: 'fill' }");
w.dirText = dirGroup.add("EditText { characters: 30, justify: 'left', " +
"text:'" + DEFAULT_MAC_DOCKETS + "'}");
w.dirBrowseBtn = dirGroup.add("Button { text: 'Browse...' }");
w.dirBrowseBtn.textBox = w.dirText;
//Package Options
w.options = w.add("Panel { orientation: 'column', alignment: 'fill', \
text: 'Package Options', alignChildren: 'left'}");
w.options.fonts = w.options.add("Checkbox { text: 'Copy Fonts' }");
w.options.links = w.options.add("Checkbox { text: 'Copy Linked Graphics' }");
w.options.profiles = w.options.add("Checkbox { text: 'Copy Color Profiles' }");
w.options.update = w.options.add("Checkbox { text: 'Update Graphic Links In Package' }");
w.options.hiddenContent = w.options.add("Checkbox { text: 'Include Fonts and Links From Hidden and Non-Printing Content' }");
w.options.ignore = w.options.add("Checkbox { text: 'Ignore Preflight Errors' }");
w.options.report = w.options.add("Checkbox { text: 'Create Report' }");
w.options.fonts.value = true;
w.options.links.value = true;
w.options.profiles.value = true;
w.options.update.value = true;
w.options.hiddenContent.value = true;
w.options.ignore.value = true; //Parham's request for true
w.options.report.value = false; //Saeed's request for false (no instructions)
//Digital Proof
w.proof = w.add("Panel { orientation: 'column', alignment: 'fill', \
text: 'Digital Proof', alignChildren: 'left'}");
w.proof.make = w.proof.add("Checkbox { text: 'Make PDF Proof' }");
w.proof.viewAfter = w.proof.add("Checkbox { text: 'View PDF' }");
w.proof.make.value = false;
w.proof.viewAfter.value = false;
//OK / Cancel
var buttonDef = "Group { orientation: 'row', alignment: 'right', alignChildren: 'right' }";
w.bg = w.add(buttonDef);
var okDef = "Button { text: 'OK', alignment: 'right' }";
var cancelDef = "Button { text: 'Cancel', alignment: ['right', 'center'] }";
w.okBtn = w.bg.add(okDef);
w.cancelBtn = w.bg.add(cancelDef);
return w;
})();
runtime.window = window;
window.dirBrowseBtn.onClick = (function () {
var result = Folder.selectDialog('Choose destination directory');
if (null !== result) {
//Replace string with selected path
this.textBox.text = result.fullName;
}
});
return window.show();
}
function deleteFolder(folder) {
if (!folder.exists) {
return;
}
var children = folder.getFiles();
for (var i = 0, im = children.length; i < im; i++) {
if (children instanceof Folder) {
deleteFolder(children);
} else {
children.remove();
}
}
folder.remove();
}
//Main path
try {
var a = app.activeDocument;
} catch (e) {
Err.FatalError("No document open");
}
var runtime = {};
var doc = app.activeDocument;
runtime.doc = doc;
if (doc.saved) {
//Document has already been saved (already has a name), so stop.
Err.FatalError("Document has already been saved");
}
//Ensure at least one link, since multipaged PDFs end up as more than 1 link.
if (doc.links.length < 1) {
Err.FatalError("Document has " + doc.links.length + " links.");
}
//Save the existing file in a temporary place, same dir as first link.
//Take the name from the first link
var link = doc.links.firstItem();
var defaultName = link.name;
if (defaultName.slice(-4) == '.pdf') {
var origlength = defaultName.length;
defaultName = defaultName.substr(0, origlength - 4);
} else {
//Placed item is not a pdf, as per Parham's request, don't warn about it.
//Just take the filename best guess and go with it.
// if (confirm('Linked item is not a PDF. Package anyways?',
// true, 'Package non-PDF')) {
//break on the last '.'
var lastIndex = defaultName.lastIndexOf('.');
if (lastIndex > -1) {
defaultName = defaultName.substr(0, lastIndex);
} else {
defaultName = defaultName;
}
// } else {
// alert('Did not package.');
// exit();
// }
}
//filePath should be a File, but is actually a string, so make a file.
var linkFile = new File(link.filePath);
var origFile = new File(linkFile.path + '/' + defaultName + '.indd');
if (origFile.exists) {
//Folder already exists, get user to confirm
if (confirm("File " + defaultName + '.indd already exists. Replace?',
true, 'Replace File')) {
//Erase the temp file
origFile.remove();
} else {
alert('Did not overwrite existing files, did not package.');
exit();
}
}
doc.save(origFile);
if (2 == makeShowUI(runtime)) {
//User pressed cancel
exit();
}
//Main code, do the packaging and make the directories.
//But first check for existing folder.
var folderName = runtime.window.folderText.text;
var destinationPath = runtime.window.dirText.text;
if (destinationPath.slice(-1) == '/') {
var newFolderPath = destinationPath + folderName;
} else {
var newFolderPath = destinationPath + '/' + folderName;
}
var outputRoot = new Folder(newFolderPath);
if (outputRoot instanceof Folder && outputRoot.exists) {
//Folder already exists, get user to confirm
if (confirm('Dockets folder ' + folderName + ' already exists. Replace?',
true, 'Replace Folder')) {
//Erase the destination directory
//Get all contained files + folders, then delete them.
deleteFolder(outputRoot);
} else {
alert('Did not overwrite existing files.');
exit();
}
} else if (outputRoot instanceof File) {
//Destination folder exists as a file, fail.
Err.FatalError('File named ' + folderName + ' already exists, cannot make folder.');
}
//Destination doesn't exist, create it.
if (!outputRoot.create()) {
Err.FatalError('Error creating folder ' + folderName);
}
//We have an empty directory, now do the packaging and everything else.
var printFolder = new Folder(newFolderPath);
printFolder.changePath(PRINT_FOLDER);
if (!printFolder.create()) {
Err.FatalError('Error creating Print folder.');
}
var digitalProofFolder = new Folder(newFolderPath);
digitalProofFolder.changePath(DIGITAL_PROOF_FOLDER);
if (!digitalProofFolder.create()) {
Err.FatalError('Error creating Digital Proof folder.');
}
var clientFolder = new Folder(newFolderPath);
clientFolder.changePath(CLIENT_FOLDER);
if (!clientFolder.create()) {
Err.FatalError('Error creating Client folder.');
}
var originalsFolder = new Folder(newFolderPath);
originalsFolder.changePath(ORIGINALS_FOLDER);
if (!originalsFolder.create()) {
Err.FatalError('Error creating Originals folder.');
}
//Do the package
var f = runtime.window.options;
if (doc.packageForPrint(originalsFolder, f.fonts.value, f.links.value, f.profiles.value, f.update.value, f.hiddenContent.value, f.ignore.value, f.report.value, false, true)) {
} else {
Err.FatalError('Failed to package.');
}
//Do the PDF proof
if (runtime.window.proof.make.value) {
var proofname = PROOF_PREFIX + doc.name;
if (proofname.slice(-5) == '.indd') {
var origlength = proofname.length;
proofname = proofname.substr(0, origlength - 5);
}
proofname = proofname + '.pdf';
var proofFile = new File(digitalProofFolder.fullName + '/' + proofname);
if (proofFile.exists) {
Err.FatalError('Digital proof already exists.');
} else {
var exportProfile = app.pdfExportPresets.itemByName(PDF_PROFILE);
//We get an object even if the profile doesn't exist, have to check isValid
if (!exportProfile.isValid) {
Err.FatalError('PDF profile ' + PDF_PROFILE + " doesn't exist, digital proof not created.");
}
//Explicitly set to export all pages.
app.pdfExportPreferences.pageRange = PageRange.ALL_PAGES;
//Set view preference
app.pdfExportPreferences.viewPDF = runtime.window.proof.viewAfter.value;
doc.exportFile(ExportFormat.PDF_TYPE, proofFile, false, exportProfile);
}
}
//Open the Originals folder .indd, close the current file and delete it.
var newFile = new File(originalsFolder.fullName + '/' + doc.name);
if (!app.open(newFile)) {
Err.FatalError("Failed to open packaged .indd");
}
Copy link to clipboard
Copied
Hi
Parham took my advice and hired me and I got to the route of the problem
The packageForPrint method has changed for 2014. it now has a couple of extra variables that aren't in the previous versions.
The extra one being include pdf (which at least on Parham's system was set as true) and include idml file.
When these values weren't the pdf was being included in a way that messed things up.
The fix was simple, it just took a little bit of time to get to the route of the problem.
I think it's about time we stated a what's change post, so I think I shall do that now.
Trevor
if (CC2014) {
if (doc.packageForPrint(originalsFolder, f.fonts.value, f.links.value, f.profiles.value, f.update.value, f.hiddenContent.value, f.ignore.value, f.report.value, f.idml.value, f.pdf.value, undefined, undefined, true)) {
} else {
Err.FatalError('Failed to package.');
}
}
else { // pre CC014
if (doc.packageForPrint(originalsFolder, f.fonts.value, f.links.value, f.profiles.value, f.update.value, f.hiddenContent.value, f.ignore.value, f.report.value, undefined, true)) { // needed to change false to undefined
} else {
Err.FatalError('Failed to package.');
}
}
Copy link to clipboard
Copied
Well done Trevor! Couldn't have done this without your help.

