is now part of CreativePro.com!

Creating a Batch of PDFs With a Script

80

Outputting a PDF from a well-created InDesign file is quite painless. Outputting many PDFs from many well-created InDesign files is painless too, but it can take up a lot of your time.

Thankfully, there is a script that makes an otherwise tedious task only take a moment – Batch convert from Peter Kahrel.

batch1

In this article, the focus will be on producing PDFs from InDesign files, but Peter’s script does a lot more than that. It can also output IDML, EPS, PNG, RTF, XML, JPG, and packaged files from InDesign, INX/IDML, as well as old QuarkXPress, and PageMaker files.

20140805-batch1

Peter’s site does a great job of explaining how the script works, but there are some things that are worth mentioning before diving in feet-first to use the script.

First, I can’t stress the term “well-created” often enough. If you don’t have a Document fonts folder in the same directory as the InDesign file,  it is possible to create PDFs with incorrect fonts. Justin Putney of Ajar Productions has a script that will package just the fonts used in your InDesign documents, relieving you of having to package a file just to make a Document fonts folder.

Likewise, if links have been moved, edited, or are missing, this can again result in incorrect PDFs.

Also, as Peter mentions, there is an option in the script’s dialog box called “View PDFs after exporting”. I would highly recommend deselecting this option, unless you want Adobe Acrobat to open dozens (or possibly hundreds) of PDF files as they are created.

Changing Layer Visibility With a Second Script

There is also a checkbox that allows you to run a script on each file prior to output. This can be very handy if your files require a final touch-up prior to outputting the PDFs.

batch2

For example, you might have a set of files containing a layer that has to be hidden prior to making PDFs. An additional script could be created and used with the Batch convert script to hide the layer. Using a text editor like Notepad, TextEdit, or TextWrangler, copy and paste in the following text:

//DESCRIPTION:single serving script to hide a layer called "Position"
app.activeDocument.layers.item("Position").visible = false;

Change both instances of the layer name from Position to the name of the layer you want to hide.

Then save the file as makelayerhidden.jsx

Now, run the Batch convert script, and in the dialog box, select the option to run an additional script, and choose your newly created makelayerhidden.jsx.

batch3

Note that this will produce PDFs with the desired layer hidden, but unless you also select the option to Save changed documents on closing, the next time you open your INDD files, the layer will again be visible.

Mapping Spot Colors With a Second Script

Another reason why you might want to use a second script is to map a customer’s spot color to a known Pantone color. In the example below, the customer’s spot color is “FIRE ENGINE RED,” but the spot color it has to match is Pantone 485, and that is not currently in the InDesign files. The script is:

//DESCRIPTION:Map color FIRE ENGINE RED to PANTONE 485 C if it isn't there app.activeDocument.importAdobeSwatchbookSpotColor ("PANTONE 485 C"); myInk = app.activeDocument.inks.item("FIRE ENGINE RED"); myInk.aliasInkName ="PANTONE 485 C";

These are only two simple examples. The Batch convert script’s ability to run another script before output can save hours of production time.

It is worth noting that this is not the only script that can run other scripts.  Here are a few that I’ve found useful.

  • For those wanting to apply many scripts to many InDesign files, Kasyan Servetsky has a script that will do just that.
  • Loic Aigon has a user interface that allows a similar batch process script to be performed on one file.
  • Rorohiko has its own version of an “InDesign Action Palette” called Action recorder. At the time of writing it is still in the Beta phase.

And finally, while you can download the Batch convert script for free, consider using the Make a Donation button on Peter’s site if you use the script and find it worthwhile. Support great scripters and their work!

A prepress operator and graphic designer for a South Australian commercial printer, with close to 20 years of experience in the trade. He is also a regular contributor to this site and InDesign Magazine, and hosts his own prepress blog "Colecandoo".
  • Gary Stolz says:

    Wow. Thanks for this! It will be a HUGE productivity boost for me!

  • Eugene Tyson says:

    Amazing, I just wrote a sorta article on this earlier today. It’s a fantastic script and I highly recommend it.

  • Mike Wagner says:

    Holy crap, this is amazing! I’m definitely going to have a use for this!

  • James Wamser says:

    Thanks, this is REALLY useful. Thanks for stressing “well-created”… Working for a commercial printer, we see a lot of well-intended, but not always well-created files.

  • David Ramirez says:

    Colin, you had me intrigued: I believe a usual workflow when working for print is sending a pdf to a commercial printer as opposed to creating a package(because of the huge amount of data). So, when you know before hand that you will be sending a pdf (properly created with correct resolution, color profile, etc) then there is no need to create a package..so fonts you use will remain in the OS folder (e.g. Windows/Fonts) and not in the same directory of the Indesign file. Why would this result in a not “well-created file”?…if for some reason (like opening an Indesign file in another pc) fonts are missing, Indesign has many alarms that make sure you are aware of it.

    • Hello there David.

      It is important to note that Peter’s script has the ability to ignore error dialog boxes, so if InDesign files have missing links or fonts, it is possible for the script to ignore these warnings and output PDFs with unexpected results.

      My point being was if using the script with the “ignore errors” checkbox on, then one would want to make darn sure that the files were prepared in such a fashion that – if opened individually – none of the files would yield any errors as they were being opened – and this is what was meant by “well-created”.

      As for “usual workflow”… that all depends on the housekeeping of the designers supplying the artwork. Not everybody follows world’s best practice, and I’ve lost count of the amount of times over the years that I’ve had to contact clients because the final output PDF was not appropriate for print purposes (for dozens of reasons) or that the native artwork supplied – again – was not appropriate (again, for dozens of reasons).

  • David Ramirez says:

    Hi Colin, you are right, when dealing with several documents you do what want to be sure that your files have no issues.
    The Copy Fonts to Folder script is awesome!

  • Gary Stolz says:

    Thanks again. Today I used it to reduce 30 minutes of work to less than 30 seconds, and they all came out perfectly.

  • Mathais says:

    Wow! Love that script! It’s worth a donation! (…I donated 10 GBP…)

    And thanks IDS for pointing me to this handy script!
    Mathais

  • Kim says:

    Is this a windows only script?

  • Morgan says:

    Sorry for the basic question, but how do I get the dialog box to open? When I click on the script, a notepad with jumbled text appears.

    • Mathais says:

      DON’T open the script in the finder or on your desktop! You must install it TO InDesign!

      So, install the script, then click (in the floating panel of InDesign) on the scripts name. Now, the dialogue should open.

  • Pure genius! Thanks so much.

  • Tony says:

    Hi all,
    Is it possible to make this script exporting the predefined ranges? I have several indd documents, which are finaly joined into the book. And I need to export all pages but not as a single PDF, but some PDF are two pages (the most of) some more, some only one. And I know the pages, which should be in one PDF. Is it possible to use this (or other) script for this?
    Example: PDF1 contains pages 1-2, PDF2=3+4, PDF3=5 to 8, PDF4=9, etc.
    Thanks!

    • Cheeky says:

      Hi Tony,
      I’m using this script with the same problem. Did anyone ever give you an answer on this? I want to be able to specify pages for pdf export.

  • Jay says:

    I knew there had to be a quicker way! Thanks so much for this. Saved me from having to convert almost 200 InDesign files individually. This worked fantastically.

  • Stefa says:

    How do I run this script with Bleeds included in the export?
    Thanks

  • fi says:

    Hi,

    This is great , it saved out all the single PDFs as I wanted but I dont appear to be able to save the PDF’s with Bleed or Cropped marks?? Have I missing something here? Please help!

    • fi says:

      Manage to get it with Bleeds! Incase any one esle was struggling. You need to set up a new Modified PDF preset in Indesign with what ever Bleeds,crop marks etc that your after. Once you have set that up , you can then select this PDF preset in the drop down in Batch process. :)

  • Rachel says:

    Is there any way to change the names of the PDFs on export? For example I regularly produce two PDFs from the documents, called xxxx that need to be called xxxx nocrops.pdf and xxxx crops.pdf – I have these set up as a preset so can export with the correct setting but can’t see a way to change it so they don’t export as xxxx.pdf

  • Yes. You need to make a javascript much like the one-line javascripts shown here and it needs to contain the following code:

    var myPDFprint = app.pdfExportPresets.item(“YOUR PRINT EXPORT PDF PRESET HERE”);
    var myPDFweb = app.pdfExportPresets.item(“YOUR WEB EXPORT PDF PRESET HERE”);
    app.pdfExportPreferences.viewPDF = false;
    app.activeDocument.exportFile(ExportFormat.pdfType, File(app.activeDocument.filePath + “/” + app.activeDocument.name.split(“.indd”)[0] + “_print.pdf”), false, myPDFprint);
    app.activeDocument.exportFile(ExportFormat.pdfType, File(app.activeDocument.filePath + “/” + app.activeDocument.name.split(“.indd”)[0] + “_web.pdf”), false, myPDFweb);

    So swap out the YOUR PRINT EXPORT PDF PRESET HERE for the name of your print PDF preset EXACTLY as it appears in InDesign. Same thing with the web preset line – swap out the YOUR WEB EXPORT PDF PRESET HERE for the name of your web PDF preset.

    When you run the batch convert script, the source should be InDesign, the target should be InDesign, and the “Run a script” dropdown should point to the 5-line javascript above that was saved.

    • You’ll also need to swap the typographers quotes with straight quotes from my last post. That is something this commenting software has done to my script :(

      • Yes, sorry about that Colin. By default, our site CMS changes the quotes. If you want to avoid that in the future, use the code and pre html tags around it. For example:

        This is a test of typing some "double quotes" and some 'single quotes' around text.
             It should also save the spaces at the beginning of
             these lines
             which usually get stripped out.
        


        (Unfortunately, it also won’t wrap properly. We’ll see if we can fix that.)

    • Peter Kahrel says:

      Colin,

      Nice examples of scripts that are run as additional scripts in the batch processor. However, recently I realised (after a user reported some problems) that variable and function names in the additional script must be ringfenced so that they don’t interfere with similar names used in the script. For example, if the additional script uses a variable i, then this will throw off any variable i used in the batch processor.

      To ringfence the additional script, wrap it as follows:

      (function () {
      // your code goes here
      }());

      Peter

  • Brett says:

    My documents have slug info on the pastes board with dimensions, if I use the batch convert it converts all my units from inches to mm, if I export individually through InDesign everything stays inches, as it should be. Is there anyway to specify units?

  • luiz says:

    Hi

    I need some help with parameters for two paths and one pdf in each folder. Eg like this:

    INDD FILE to
    PDF _High (path/ folder 1 /PRESS)
    PDF _low (path/ folder 2 /REWIEW)

    Of course, the destination folders are already well in place.

    This script need to be edited to this end. Is possible?

    d = app.activeDocument;
    preset1 = app.pdfExportPresets.itemByName(“[Smallest File Size]”);
    preset2 = app.pdfExportPresets.itemByName(“[Press Quality]”);
    if (!(preset1.isValid && preset2.isValid)){
    alert(“One of the presets does not exist. Please check spelling carefully.”);
    exit();
    }

    mDocName = d.name.substr (0, d.name.lastIndexOf(‘.’));
    mSourcePath = d.fullName.parent.toString();
    mRootPath =mSourcePath.substr (0, mSourcePath.lastIndexOf(‘/’));
    mTargetPath=mRootPath.concat(‘/final/’);

    mNamePrint = mTargetPath.concat(mDocName,’.pdf’);
    mNameWeb= mTargetPath.concat(mDocName,’_baixa.pdf’);

    if (!d.saved){
    d.save;
    }

    d.exportFile(ExportFormat.PDF_TYPE, new File(mNamePrint), false, preset1);
    d.exportFile(ExportFormat.PDF_TYPE, new File(mNameWeb), false, preset2);

  • Joseph Blunden says:

    I am now getting an error any time I try to use it:
    “undefined is not an object (line 721)”

  • Gauthier says:

    Hi,

    I’m on Indesign cc 2015 (december 2015) and I have the same error :
    In the begin, the script work, and after 2 ou 3 export, the script did not work :
    “undefined is not an object (line 721)”

    The script is great, it will be good to have a solution !

    Thanks

    • I think the best thing to do is get in touch with the author of the script, Peter Kahrel, and let him know what is going on. Go to https://www.kahrel.plus.com/info.html and click the “contact me here” link.

      Make sure to provide the following information:

      1) The version of InDesign you are using (as well as your operating system AND language version of InDesign you are using;
      2) The steps that were taken in order for this error to occur.

      • Peter Kahrel says:

        Thanks, Colin, and thanks too for the post on this script, much appreciated.
        Peter

      • Gauthier says:

        Thank you Colin for your answer. Peter gave me the solution by mail, and he post this under this post.

        Thanks to the community !

    • Peter Kahrel says:

      The script clearly needs a fix, and I’ll do that soon. In the meantime you should be able to fix this by deleting the script’s configuration file. It’s called batch_convert.txt and lives in the same folder as the script. You can see the txt file in InDesign’s Scripts panel, greyed out (if you can’t see it, select ‘Display unsupported files’ in the Script panel’s menu). Right-click the txt file and select ‘Delete script file’, then run the script again.

  • Nic Neame says:

    Thanks Peter! Removing the .txt file worked a treat. Honestly this is the best script ever! If you update it in the future I’d happily pay for anything new that you create! Nic :D

  • Chrystina Hanna says:

    This is a fantastic script, saving me hours!!! But I’m having the same issue as someone above me posted: Upon exporting, I need the names of the pdf’s to be xx-OKC and don’t see how to change this. Thanks so much for the script and any advice!!!

  • David says:

    I’m having trouble loading the script. I placed the file in the user folder and it appears in the script panel but when I double click the script, or select Run from the fly-out menu, nothing happens. I believe that I am doing everything correctly – not having any documents opened when I try to run the script and I’ve also tried the script with files open.

    If it helps, I am trying to use the script on a work computer using Indesign CC 2015.

    • I’ve noticed when using InDesign CC with the El Capitan system, that when a script is running and a progress bar would usually appear, the progress bars now seem to disappear.

      In relation to your issue, I’m not sure, but you would need to ask the author of the script.

      • Peter Kahrel says:

        Hi Colin — InDesign’s Scripts panel menu has an option ‘Enable Redraw’. Is that option checked? If not, please check it and see what happens.

  • Peter Kahrel says:

    David — Did you unzip the file download? You should copy the .jsxbin file to the Scripts folder, not the zip file. Other than that I can’t tell you much. If there’s not even an error message there’s not much to go on.

    • David says:

      I did unzip the file and copied the file over to the Users script folder. The zip file that I downloaded did not have the batch_convert.txt file, which I’m assuming is okay since the troubleshooting section mentions to remove it. I will continue trying. Hopefully, it will either work or I will get an error message that I can report.

  • Marcus says:

    You’re a star. A shining one!

  • Darius Detwiler says:

    Sorry, it does not work. The Input Folder entry will not activate and allow to enter folder information. Only the Output Folder works, so I can only convert one document at a time, not as a batch. Tried several times to download and reload the script: the results are the same. Using CC 2015.

    • Peter Kahrel says:

      The input field is disabled when you have one or more documents open. Therefore close all documents, then run the script. Now you can enter a folder.

  • elena says:

    i have a batch of indd book files,
    is there a way to select indb files to convert batch?

  • joseph says:

    Firstly, thank you for this script! It’s increased my productivity significantly!

    My Javascript knowledge is very basic so maybe someone can help me out. I wanted to run a secondary script that converts/maps the default blacks to rich blacks for production. This would apply to text and background colours.

    Does anyone have a script for that?

    Thanks again!

  • Erik says:

    Hi, the script does not work on my InDesign CC 2017. Is it compatible with this version??

    • Peter Kahrel says:

      Yes, it is compatible with CC2017.
      In what way does it not work? Do you see any error messages? What are you trying to do?

      P.

      • Erik says:

        Thanx for your answer! When I’m trying to double click/run the script it says “undefined is not an object (line 848)

      • Erik says:

        I want to export PDFs from 40 different InDesign files. But when I run batch_convert.jsxbin the message pops up…

  • Erik says:

    Now I got the script running and the thing I want to do works if I open all the documents and does the thing. Not possible to choose input folder thou and make it that way. MANY THANX FOR A WONDERFUL SCRIPT!!!!!!

    • Peter Kahrel says:

      If you can’t choose the input folder (if that field is disabled) then there is a document open (could be, even if you don’t see it). Close InDesign and restart it. Also, if there’s a text file batch_convert.txt in your Scripts folder, delete that and run the script again.

  • Suzanne Ammon says:

    I installed the batch convert script, It worked fine the first time, but now when I open the script and locate indesign documents they are shaded grey, so I can’t click on them.

    I also tried to install the scripts on the other macs in my office and, it is doing the same thing thinking maybe can’t install on more than 1 system in the office. Please help me solve this problem, I have to pdf alot of documents on a weekly basis and this would be a god send

    • Peter Kahrel says:

      What do you mean when you say “locate indesign documents they are shaded grey, so I can’t click on them.” If script’s input field is greyed out you have some documents open. Close them and try again. Other possibility: delete the batch_convert.txt file that’s in the Scripts panel. If that’s still not it, please post a screen shot that shows what you mean.

      As to “maybe can’t install on more than 1 system”, no, it’s a script, you can install it as many times as you like.

    • Peter Kahrel says:

      (I received your reply — with screenshot — via David Blatner. If you send your reply via email, it doesn’t make it to the forum and no-one will see it apart from DB.)

      Never seen that problem before. Exit InDesign. If it asks if you want to save one or more documents even if you can’t see any, say ‘No’. Then start InDesign again and run the script again.

  • Brett Cox says:

    Hey Colin

    Thanks for the script – just an issue with the layers script. It is hiding the layer I’ve stated – I get an error at the end “Syntax error (at line 103)”.

    Any ideas?

  • Abhijeet says:

    please modify the script so that package should be created at same path where .indd is placed

  • Eva says:

    Hi,

    the script is amazing, I just spotted one problem when I try to convert idml to PDF or Indd files, it appears a message of “object is invalid (296)”. Any idea of what could happen?

    • Peter Kahrel says:

      Eva — The script works fine here converting idml to indd and pdf. First thing to try is to delete the config file, batch_convert.txt, which lives in the same folder as the script. If that doesn’t help, please post a screenshot of the script’s interface with the settings that you use.

      P.

      • Adil says:

        Hi, first of all thank you for the script. Now I am using this script to convert p65 (pagemaker doc) to pdf but I have been receiving the same error as Eva. Additionally I am also getting the error “Problem closing ” I tried this for p65, p7 and pmd files but I got the same result. I also do not have any config file or batch_convert.txt in the script folder. Please note that when I ran this script for the first time, it successfully converted 1 of 6 pmd files to pdf.

  • Stefanie Hausner says:

    I’m loving this script and it’s helping SO much with productivity. Similarly, I’m looking for a script that would save a single PDF from InDesign to multiple locations. Our production has several distribution points, and it would help with consistency and save time. Does anyone know of one that may exist like that?

  • Masood Ahmad says:

    @peter, your script works very well and I use it more often, when I have to export a number of PDFs. Is it possible somehow to batch convert both IDML and PDF in one go. Currently I export PDFs and then IDMLs.

    • Yes, you can do this if you batch convert ID files to ID files, and then run a script that will export to the myriad formats that you require. That part of the code you need to write/have written, but it can be executed from Peter’s script by using the “run a script” checkbox in the UI of the script.

  • Peter Kahrel says:

    That would mean some serious surgery on the script, so in effect, I’m afraid that it’s not possible.

    • Masood Ahmad says:

      I too have the same thoughts :) Meanwhile I’m okay with the current version.

    • Masood Ahmad says:

      Hi Peter, I have another task for you and I posted it in another post.

      I want your script to make individual packages, with an option to create Print and Web pdf using respective pdf presets.

  • Jaz says:

    Since I got my InDesign updated to 13.1 the script isn’t working anymore. Any idea how I can change that?

  • Steven R. says:

    Hi there ;-)

    This script is absolutely genius!!! I have a special situation though:
    I have ONE InDesign-Document containing FIVE layers (German, French, Italian, Spanisch and English). What would be cool is to have the script perform following task: Open .indd-File with only German layer active, save PDF, close without saving, open the same .indd-File again, hide German layer, activate French layer, save PDF, close without saving, open .indd-File again, hide German layer, activate Italian layer, save PDF…. etc

    Would that be possible? Or would I need a special seperate script?

    Thanks for any ideas and have a nice day!

    Cheers,
    Steven R.

  • hamid says:

    Hi
    ……………………
    the document page size exceeds the page size range supported in pdf files. exported pages will be resized to fit within pdf limits.
    ……………………
    I have this massage, what should I do, how to fix ti?
    please show me the solution.

    • Peter Kahrel says:

      I’ve never seen that error. It suggests that your InDesign files have large page sizes, larger than is allowed in PDFs. Reduce the page sizes in InDesign or accept that the pages are resized during PDF-export.
      P.

  • Patrick Flowers says:

    I use this in multiple ways, and it has saved tons of time! Batch exporting 10-15 files for a proofreader used to take lots of time opening each file, updating any links, and waiting to export. Now I can *insert Ron Popiel here* Set it and forget it!

    However, I’ve run into a weird issue on this, which hasn’t happened before 6-8 months ago –
    Whenever I run the processor for Source INDD to Target INDD (used whenever CC updates to a new year, for example, or I need to update older files to be usable for new designers who might not have specific versions), it causes the INDD to disappear for some users.
    I can see it just fine, the permissions aren’t any different, but I have to run the batch processor again and they end up seeing the file eventually. It’s not every file or every directory, just on occasion after running through the processor. Any thoughts?

  • >