Copy link to clipboard
Copied
I'm looking for a script that can export png's or jpgs or pdf's. Anything that can be viewed without having indesign on your computer. Does anyone know of one? I've tried the batch export script from Peter Kahrel and it doesn't quite work for me as it takes about 3 minutes per document. Is there anything else that can accomplish this faster? I tried bridge, but the jpgs it exports are tiny for some reason. Can't figure it out.
Thanks in advance!
Scott
I mean, if you just want to export all open documents as pdfs with no extra fuss, this would work. The time it takes would be dependent on the complexity of the file to export, just as if it were done manually. This assumes your ID has the PDF/x1a preset loaded.
var outputToPdf = function(doc, folder) {
var exportFile = new File(folder.fsName + "/" + doc.name.slice(0,doc.name.lastIndexOf(".")) + ".pdf");
var px1aPreset = app.pdfExportPresets.itemByName("[PDF/X-1a:2001]");
try {
...
Right, I guess that's a popup when you open a doc, not a preflight thing.
After the var folder selectDialog line, you can try the following lines:
var currInteractPrefs = app.scriptPreferences.userInteractionLevel;
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;
At the end of the script, be sure to set the prefs back to the way they were:
app.scriptPreferences.userInteractionLevel = currInteractPrefs;
Copy link to clipboard
Copied
I mean, if you just want to export all open documents as pdfs with no extra fuss, this would work. The time it takes would be dependent on the complexity of the file to export, just as if it were done manually. This assumes your ID has the PDF/x1a preset loaded.
var outputToPdf = function(doc, folder) {
var exportFile = new File(folder.fsName + "/" + doc.name.slice(0,doc.name.lastIndexOf(".")) + ".pdf");
var px1aPreset = app.pdfExportPresets.itemByName("[PDF/X-1a:2001]");
try {
doc.exportFile(ExportFormat.PDF_TYPE, exportFile, false, px1aPreset);
} catch(e) {
alert("Couldn't export " + exportFile.name + " for this reason: " + e);
}
};
var folder = Folder.selectDialog("Please select a folder to save to");
var docs = app.documents;
for (var i = 0; i < docs.length; i++) {
outputToPdf(docs[i], folder);
}
Copy link to clipboard
Copied
Hmm. I'm getting a javascript error. "documents not defined." Any idea on a quick fix?
Copy link to clipboard
Copied
Oops, change documents.length to docs.length in the for loop. I just edited the original code.
Copy link to clipboard
Copied
Shoot, now I'm getting an error for "Invalid value for parameter 'showingOptions' of method 'exportFile'. Expected Boolean, but received PDFExportPreset.
Any ideas?
Thanks!
Copy link to clipboard
Copied
That's what I get for not actually testing š
Try the edited code now.
Copy link to clipboard
Copied
You're the man Brian!
Do you know if there is a way to do this to a whole directory of files?
Would something like this work with this script? This is for a different script that packages all files within a folder structure.
var myFolder = Folder.selectDialog("Select a folder with INDD files to package");
if (myFolder == null) exit();
var myFilelist = [];
var myAllFilesList = myFolder.getFiles();
for (var f = 0; f < myAllFilesList.length; f++) {
var myFile = myAllFilesList[f];
if (myFile instanceof File && myFile.name.match(/\.indd$/i)) {
myFilelist.push(myFile);
}
}
if (myFilelist.length == 0) {
alert("No files to open.", "Package for Aprimo");
exit();
}
Copy link to clipboard
Copied
Sure. Rather than var docs = app.documents, you'd do this:
var docs = app.open(myFilelist, false);
If you want to see them open in the window, you'd change false to true. False opens the doc but doesn't display it in the window. Might speed things up a tad.
Copy link to clipboard
Copied
Hey Brian, thanks for all your help with this! Do you know how I would pass over missing links? Just ignore the dialogue box that would come up? Also ignore updated links as well?
Many thanks!
Scott
Copy link to clipboard
Copied
You can turn the preflight options off with:
Copy link to clipboard
Copied
Hmmm. That didn't seem to work. Any ideas?
Copy link to clipboard
Copied
You need to set it for each doc you open.
docs[i].preflightOptions.preflightOff = true;
Copy link to clipboard
Copied
I'm still not getting it to work. Where would you place this in the script?
Thanks!
Copy link to clipboard
Copied
at the top of the outputToPdf function:
var outputToPdf = function(doc, folder) {
doc.preflightOptions.preflightOff = true;
...
};
Copy link to clipboard
Copied
I still can't get it to work. Here's the code exactly as I have it.
var outputToPdf = function (doc, folder) {
doc.preflightOptions.preflightOff = true;
var exportFile = new File(folder.fsName + "/" + doc.name.slice(0, doc.name.lastIndexOf(".")) + ".pdf");
var px1aPreset = app.pdfExportPresets.itemByName("Aprimo Audit");
try {
doc.exportFile(ExportFormat.PDF_TYPE, exportFile, false, px1aPreset);
} catch (e) {
alert("Couldn't export " + exportFile.name + " for this reason: " + e);
}
};
var myFolder = Folder.selectDialog("Select a folder with INDD files to export");
if (myFolder == null) exit();
var myFilelist = [];
var myAllFilesList = myFolder.getFiles();
for (var f = 0; f < myAllFilesList.length; f++) {
var myFile = myAllFilesList[f];
if (myFile instanceof File && myFile.name.match(/\.indd$/i)) {
myFilelist.push(myFile);
}
}
if (myFilelist.length == 0) {
alert("No files to open.", "Export to PDF");
exit();
}
var folder = Folder.selectDialog("Please select a folder to save to");
var docs = app.open(myFilelist, false);
for (var i = 0; i < docs.length; i++) {
outputToPdf(docs[i], folder);
}
Copy link to clipboard
Copied
How exactly does it not work? Error message? Popup still popping up?
Copy link to clipboard
Copied
Yeah it has the same dialogue box as it did before asking about missing links.
Copy link to clipboard
Copied
Right, I guess that's a popup when you open a doc, not a preflight thing.
After the var folder selectDialog line, you can try the following lines:
var currInteractPrefs = app.scriptPreferences.userInteractionLevel;
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;
At the end of the script, be sure to set the prefs back to the way they were:
app.scriptPreferences.userInteractionLevel = currInteractPrefs;
Copy link to clipboard
Copied
Boom. That works. Thanks man! You have helped me immensely!
Copy link to clipboard
Copied
Brian, one last question. I'm sorry for bombarding you with questions and I'm so happy you were able to help me out! Is there a way to disable the preview of the pdf after creation? I'll be using this to make 22,000 pdfs and I'd rather not have each one open up after creation. Thank you!!
Copy link to clipboard
Copied
Add this somewhere:
app.pdfExportPreference.viewPDF = false;
Donations are always graciously appreciated. Feel free to PM for PayPal info. Cheers!
Copy link to clipboard
Copied
I absolutely will! One last question, I'm getting some errors, I believe due to too many documents opening in InDesign, as I'm trying to output from about a thousand documents at once. Is there a way to make the script do one doc at a time? Open one doc, export pdf, then close the doc? Thank you so much for all the help! I'll pm you for paypal right now. Thanks Brian!
Copy link to clipboard
Copied
Yeah, that would do it! Rather than opening them all at once, adjust the bottom of the script to this. You might want to break into a couple chunks of say, 350 files in each folder anyway:
var folder = Folder.selectDialog("Please select a folder to save to");
for (var i = 0; i < myFilelist.length; i++) {
var doc = app.open(myFilelist[i], false);
outputToPdf(doc, folder);
doc.close(SaveOptions.NO);
}
Copy link to clipboard
Copied
What do I adjust the bottom of the script to?
Edit** That works, I think! I misunderstood your comment. Thank you!
Copy link to clipboard
Copied
Hi All,
Where or who can I buy a script from that does batch Package of InDesign files and creates a PDF & JPEG or whatever other format I need?
Thanks
Dean