CreativePro Forum
Join our community of graphic designers, publishers, and production artists from around the world. Our members-only forum is a great place to discuss challenges and find solutions!
- You must be logged in to reply to this topic.Login
Batch converting Indesign files to PDF
- This topic has 3 replies, 4 voices, and was last updated 12 years, 8 months ago by
pconley.
-
AuthorPosts
-
-
July 21, 2011 at 11:32 am #60113
Blondie123
ParticipantI am trying to take about 1100 1-page indesign files all located in one folder (but each in their own respective subfolders) and batch convert them all to PDF's all in one folder. I would also like to preserve the file name, so the corresponding indesign can be found easily. Basically I am trying to make a PDF library of all the indesign files in this folder. I would like to update it every so often, so I would like it to be as seamless as possible.
I tried to do this with this script: https://www.kahrel.plus.com/indesign/batch_convert_cs3.html , which worked perfectly when I transferred all the files over to CS5, but for some reason, when I batch convert the files to PDF, about 20% of the PDF's made came up as empty files (they looked like they were made correctly, but the size is 0 KB, and they don't open, of course). I even tried doing it in small batches (about 10 files), and I was still getting empty files. I don't understand why- I can't find anything similar about the files that are coming up empty, and when I open and export them myself, they export just fine. I have also converted while not having the “ignore errors” checked, and no errors come up.
I have also tried just putting all the indesign files in one folder, and having Acrobat convert them, but when I do that, acrobat tries, but then says it does not recognize the program that made these files; I don't know why.
For reference, I am using indesign CS5 on a PC and Adobe acrobat 9 Pro.
I personally do not know how to script, but I use scripts often. If someone knows another script I could use to do the same thing, I would appreciate that. Otherwise, if anyone can tell me if there is a way to troubleshoot this with the Kahrel script, or if there is a totally different way of doing it, I am open to suggestions!
Thanks!
-Blondie
-
July 22, 2011 at 1:57 am #60116
Kasyan Servetsky
MemberHi Blondie,
Yes, Peter's script has some issues but it's impossible to fix it because it is posted in binary format (the author doesn't want anybody ti meddle with code).
Today, while drinking my morning coffee, I wrote this script. It takes all indd-files from the selected folder and its subfolders and exports each file to pdf-format saving them in the 'Pdf' folder which is created by script. Note that there is possibility that in different subfolders can be files with identical names. The script handles this situation: it adds a sequential number to the file name so it never gets overwritten. For example: SomeFile.pdf, SomeFile.pdf(1), SomeFile.pdf(2) and so on.
For better performance the script doesn't display documents being opened and closed, but the progress bar shows which file is being processed, how many files have already been processed.
I haven't totally tested it yet — it's already time for me to go to my work — so probably I'll make some changes to it.
Hope this helps.
Regards,
Kasyan// Script for InDesign CS3-5.
// July 22 2011
// Written by Kasyan Servetsky
// https://www.kasyan.ho.com.ua
// e-mail: askoldich@yahoo.com
//======================================================================================
var gScriptName = “Batch export INDD-files to PDF”; // Name of the script
var gScriptVersion = “1.0”; // Versionvar gSet = GetSettings();
CreateDialog();//===================================== FUNCTIONS ======================================
function CreateDialog() {
var pdfPresetsList =app.pdfExportPresets.everyItem().name;
var win = new Window(“dialog”, gScriptName + ” – ” + gScriptVersion);win.p = win.add(“panel”, undefined, “”);
win.p.alignChildren = “right”;
win.p.alignment = “fill”;win.p.g = win.p.add(“group”);
win.p.g.st = win.p.g.add(“statictext”, undefined, “PDF-presets:”);
win.p.g.ddl = win.p.g.add(“dropdownlist”, undefined, pdfPresetsList);
win.p.g.ddl.selection = gSet.selectedPdfPresetIndex;
win.p.g.ddl.preferredSize.width = 220;win.buttons = win.add(“group”);
win.buttons.orientation = “row”;
win.buttons.alignment = “center”;
win.buttons.ok = win.buttons.add(“button”, undefined, “OK”, {name:”ok” });
win.buttons.cancel = win.buttons.add(“button”, undefined, “Cancel”, {name:”cancel”});var showDialog = win.show();
if (showDialog == 1) {
gSet.selectedPdfPresetIndex = win.p.g.ddl.selection.index;
app.insertLabel(“Kas_” + gScriptName + gScriptVersion, gSet.toSource());
Main();
}
}
//——————————————————————————————————————————————————–
function Main() {
var folder = Folder.selectDialog(“Select a folder with InDesign files to resave”);
if (folder == null) exit();
var files = GetFiles(folder);
var pdfFolder = new Folder(folder.fsName + “/” + “Pdf”);
VerifyFolder(pdfFolder);if (files.length == 0) {
alert(“No files to open.”, gScriptName + ” – ” + gScriptVersion);
exit();
}var pdfPresets =app.pdfExportPresets.everyItem().getElements();
var selectedPdfPreset = pdfPresets[gSet.selectedPdfPresetIndex];
var count = 1;
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;// Progress bar ———————————————————————————–
var progressWin = new Window (“window”, gScriptName + ” – ” + gScriptVersion);
var progressBar = progressWin.add (“progressbar”, [12, 12, 350, 24], 0, files.length);
var progressTxt = progressWin.add(“statictext”, undefined, “Starting exporting files”);
progressTxt.bounds = [0, 0, 340, 20];
progressTxt.alignment = “left”;
progressWin.show();
// Progress bar ———————————————————————————–for (var i = 0; i < files.length; i++) {
var currentFile = files[i];try {
var doc = app.open(currentFile, false);
var docName = doc.name;// Progress bar ———————————————————————————–
progressBar.value = count;
progressTxt.text = String(“Exporting file – ” + docName + ” (” + count + ” of ” + files.length + “)”);
// Progress bar ———————————————————————————–var file = new File(pdfFolder + “/” + GetFileName(docName) + “.pdf”);
if (file.exists) {
var increment = 1;
while (file.exists) {
file = new File(pdfFolder + “/” + GetFileName(docName) + “(” + increment++ + “).pdf”);
}
}doc.exportFile(ExportFormat.pdfType, file, false, selectedPdfPreset);
doc.close(SaveOptions.NO);
count++;
}
catch(e) {}
}// Progress bar ———————————————————————————–
progressWin.close();
// Progress bar ———————————————————————————–app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;
alert(“Done.”, gScriptName + ” – ” + gScriptVersion);
}
//——————————————————————————————————————————————————–
function VerifyFolder(folder) {
if (!folder.exists) {
var folder = new Folder(folder.absoluteURI);
var array1 = new Array();
while (!folder.exists) {
array1.push(folder);
folder = new Folder(folder.path);
}
var array2 = new Array();
while (array1.length > 0) {
folder = array1.pop();
if (folder.create()) {
array2.push(folder);
} else {
while (array2.length > 0) {
array2.pop.remove();
}
throw “Folder creation failed”;
}
}
}
}
//——————————————————————————————————————————————————–
function GetFiles(theFolder) {
var files = [],
fileList = theFolder.getFiles(),
i, file;for (i = 0; i < fileList.length; i++) {
file = fileList[i];
if (file instanceof Folder) {
files = files.concat(GetFiles(file));
}
else if (file instanceof File && file.name.match(/.indd$/i)) {
files.push(file);
}
}return files;
}
//——————————————————————————————————————————————————–
function GetFileName(fileName) {
var string = “”;
var result = fileName.lastIndexOf(“.”);
if (result == -1) {
string = fileName;
}
else {
string = fileName.substr(0, result);
}
return string;
}
//——————————————————————————————————————————————————–
function GetSettings() {
var set = eval(app.extractLabel(“Kas_” + gScriptName + gScriptVersion));
if (set == undefined) {
set = { selectedPdfPresetIndex : 0 };
}return set;
}
//——————————————————————————————————————————————————– -
August 28, 2012 at 2:31 am #62996
evernn
MemberYou write too professional, so much code let me a headache, and for me to Google search an easy-to-use PDF creator is good method. I saw one OXPDF software is very nice. Can batch conversion documents to PDF. Give you picture you see.

I didn't find any weaknesses.
-
March 26, 2013 at 11:55 pm #64499
pconley
Memberthank you for the information. i got it. Hope the method works me.
-
-
AuthorPosts
- You must be logged in to reply to this topic.
