InDesign script to batch export png, jpg or pdf

Explorer ,
Jan 02, 2020 Jan 02, 2020

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

TOPICS
Import and export , Scripting

Views

3.6K

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 2 Correct answers

Adobe Community Professional , Jan 03, 2020 Jan 03, 2020
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 { ...

Likes

Translate

Translate
Adobe Community Professional , Jan 08, 2020 Jan 08, 2020
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; Not sure if that will work or if it will jus...

Likes

Translate

Translate
Adobe Community Professional ,
Jan 03, 2020 Jan 03, 2020

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

 

 

  

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 03, 2020 Jan 03, 2020

Copy link to clipboard

Copied

Hmm. I'm getting a javascript error. "documents not defined." Any idea on a quick fix?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jan 03, 2020 Jan 03, 2020

Copy link to clipboard

Copied

Oops, change documents.length to docs.length in the for loop. I just edited the original code. 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 03, 2020 Jan 03, 2020

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!

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jan 03, 2020 Jan 03, 2020

Copy link to clipboard

Copied

That's what I get for not actually testing 🙂 

 

Try the edited code now. 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 03, 2020 Jan 03, 2020

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

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jan 03, 2020 Jan 03, 2020

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. 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 08, 2020 Jan 08, 2020

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jan 08, 2020 Jan 08, 2020

Copy link to clipboard

Copied

You can turn the preflight options off with: 

 

doc.preflightOptions.preflightOff = true;
 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 08, 2020 Jan 08, 2020

Copy link to clipboard

Copied

Hmmm. That didn't seem to work. Any ideas?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jan 08, 2020 Jan 08, 2020

Copy link to clipboard

Copied

You need to set it for each doc you open. 

docs[i].preflightOptions.preflightOff = true;

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 08, 2020 Jan 08, 2020

Copy link to clipboard

Copied

I'm still not getting it to work. Where would you place this in the script?

 

Thanks!

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jan 08, 2020 Jan 08, 2020

Copy link to clipboard

Copied

at the top of the outputToPdf function: 

 

var outputToPdf = function(doc, folder) {
    doc.preflightOptions.preflightOff = true; 
    ...
};

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 08, 2020 Jan 08, 2020

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jan 08, 2020 Jan 08, 2020

Copy link to clipboard

Copied

How exactly does it not work? Error message? Popup still popping up? 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 08, 2020 Jan 08, 2020

Copy link to clipboard

Copied

Yeah it has the same dialogue box as it did before asking about missing links.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jan 08, 2020 Jan 08, 2020

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;

 
Not sure if that will work or if it will just hang the script, but worth a shot. Otherwise, I got nothin'. 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 08, 2020 Jan 08, 2020

Copy link to clipboard

Copied

Boom. That works. Thanks man! You have helped me immensely!

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 09, 2020 Jan 09, 2020

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!!

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jan 09, 2020 Jan 09, 2020

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! 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 10, 2020 Jan 10, 2020

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!

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jan 10, 2020 Jan 10, 2020

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

 

 

 

 

 

 

 

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 11, 2020 Jan 11, 2020

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!

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 28, 2022 Feb 28, 2022

Copy link to clipboard

Copied

LATEST

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines