Members Only

Peter Kahrel’s Long Document Scripts for InDesign

Find out what these amazing InDesign scripts can do for you!

This article appears in Issue 18 of CreativePro Magazine.

For InDesign power users, it’s not a question of if, but when.

At some point, you are going to encounter a text-heavy project that you know would benefit from a script.

Maybe you’ll find yourself slogging through design and production of a dense, academic book, or series of books, with multi-language typesetting or math or science, with a complicated index, cross references, footnotes, or endnotes.

Or maybe you’ll find a persnickety irritation in InDesign that will haunt you as you open a server’s worth of files—perhaps, a font that doesn’t quite match and needs to be replaced in every file you’re going to open for the next two weeks.

That is when users discover and delight in the world and the work of Peter Kahrel—scholar, editor, designer, and JavaScript programmer.

As InDesign ascended to become an industry standard in book design and pagination, Kahrel began making his scripts freely available—dozens of them, all meticulously organized by function—as he wrote them and used them in all aspects of production of some breathtakingly complex books.

Do you want to sort a multilingual list alphabetically? Kahrel’s got it. Do you have a folder of images that need batch conversion? Yup. A need to make line edits on tables that are rotated on multiple pages in your book? Sure. He has little fixes to InDesign features that you haven’t thought about enough to realize they were broken.

For the past five years, CreativePro Networks has hosted the Kahrel archive, which was in danger of being displaced from a web server of an internet service provider that he would no longer be using.

These editorial, design, and production gems are sitting in our own backyard, in a matter of speaking, and we think our readers should know they’re there and what they might be able to do for you.

Here’s the fun part: Kahrel really never made these scripts for anyone but himself. Nobody test-marketed anything or ran anything by a focus group. He just methodically built up a collection of code that made his creative life simpler and more productive. He speaks with pride about the precision and complexity of work that this automation has made possible for his clients over the years. And he’s happy to share them with anyone who just might find them useful.

So read on, and learn about a couple dozen exceptional scripts from the archive. You can click each title to jump to that script’s page at CreativePro.com.

Batch-Process Documents (Convert/Export/Import)

Do you have a folder of InDesign files you need to print? Turn into PDFs or PNGs or JPEGs? This Swiss Army Knife of a script could become an essential tool for you. Simply select the folder with the files you want to work with, select another folder for the files you output, and configure away (Figure 1).

Dialog box "Batch Process" shows input folder, output folder, source format, target format, options for PDF, options for packaged files, miscellaneous options

Figure 1. This script turns InDesign into a powerful file conversion utility.

Font Substitution

Sooner or later, we all get irritated by having to use Find/Replace Font on a bunch of files. This script lets you automate the process, ultimately enabling you to do the find/replace process easily and accurately with one click (Figure 2).

Dialog box for Substitute Fonts shows missing fonts and menus for selecting replacements

Figure 2. The Font Substitution script lets you attack missing fonts with precision.

Dynamic Sidenotes

A book with sidenotes instead of endnotes (Figure 3) can be a lovely variant on traditional design, but it can easily become a production nightmare. This script automatically converts InDesign’s footnotes to sidenotes anchored to the main text so the notes move with the text flow (Figure 4). The script creates an array of styles for easy, consistent design tweaking. Another script can convert them back to endnotes if you change your mind.

Book page designed with sidenotes in margin

Figure 3. Designing with sidenotes can make a text with copious endnotes appear more spacious and inviting…

 

closeup of text type shows hidden character for text anchor.

Figure 4. … and the Dynamic Sidenotes script lets you execute this design with automated anchored text frames.

Page Set-up

Book designers and compositors could get some use from this script (Figure 5), which builds a document based on common publishing specifications (top margin, inside margin, and number of lines).

Dialog box for Page Set-up shows options for Trim size height, trim size width, head (top) margin, back (inside) margin, text measure, text depth (number of lines), First baseline option, typeface, type style, size, leading, default paragraph style name

Figure 5. The Page Set-up script’s parameters

Spread Rotation Menu Commands

InDesign allows you to view a spread so you can work on rotated text without getting seasick, but those commands are buried three levels deep inside the Pages panel menu. Run this script once, and a quick click of your context menu will let you rotate a spread 90° clockwise or counterclockwise (Figure 6).

Pages panel menu with additional options for rotating 90° clockwise and 90° counterclockwise

Figure 6. One script silently adds 90° rotation commands to contextual menus for the Pages panel.

Rotate Spreads

You’ve got a long document with multiple rotated tables that need corrections. You could rotate each spread manually, or you could use this script to rotate all spreads with rotated objects en masse (Figure 7). Make your edits, run the script again to revert the rotation, and blow the imaginary gun smoke from your index finger with triumphant satisfaction.

InDesign pages on screen and pages panel show second spread with horizontal table rotated

Figure 7. With one click, the Rotate Spreads script will rotate every spread in your document which contains a rotated object—perfect for editing massive numbers of rotated tables over multiple pages, as in this book project.

Show a Document’s Fonts with Type and Status

Unless you’ve been living under a tree, you know that Adobe is discontinuing support of Type 1 fonts. This script gives you a deep-dive report into all the fonts used in a document—far beyond whether a font is Type 1 or OpenType (Figure 8). It will pull information from deep within your font files, whether they’re in your own library or you’ve activated them with Adobe Fonts.

Dialog box for Document fonts shows list of fonts used with columns for typeface, style, type, and status.

Figure 8. A deep-dive report on your font usage is indispensable, especially with Type 1 fonts incompatible with the newest InDesign releases.

Price Adjuster

“Oh, by the way, we need to change all the prices in this price list from dollars to euros.”

“Oh, by the way, we need to add a $1.50 surcharge on all prices in the catalog.”

Run this script, type in the formula for conversion, configure a few options (Figure 9), and get a whole new version of your document without breaking a sweat.

Sample price list document shows range of prices before and after. Dialog box for price adjuster shows fields for operation, operator, currency symbol, separator, number format, insert thousands separator, decimals, color,

Figure 9. Need to change all prices in a document by 25%? It’s a breeze with the Price Adjuster script.

Go to a Page in any Book Document

If you’re wont to maneuver around your InDesign documents with Command/ Ctrl+J to jump to a numbered page, you will probably love this script, which lets you do the same thing with an active Book (Figure 10).

Dialog box for Go to Page, plus keyboard shortcuts dialog box that shows assignment of keyboard shortcut to script

Figure 10. You can configure your keyboard shortcuts to replace the original non-Book-savvy dialog box with the Go to Page script.

Go to the Parent Spread Applied to the Active Spread

There’s no easy way to immediately open the parent page applied to the page you’ve selected… right? Well, now there is. Run this script (Figure 11), and bam! If you’re in and out of editing templates and tweaking multiple parent pages as you build, this script will help you work more fluidly.

Top image shows front page of newspaper with arrow to image of parent page selected after invoking go_to_master.jsx

Figure 11. Effortlessly navigate to any page’s parent with the click of a script.

Move Selected Paragraphs

This set of two scripts (Figure 12) will let you move full paragraphs associated with selected text up or down. Assign them to keyboard shortcuts for quick access!

Figure 12. Move Selected Paragraphs will take full paragraphs (in magenta) associated with selected text and move them en masse through your text thread, up or down, depending on which script you use.

Manage Text Anchors

It’s not easy to see where you’ve used text anchors in your document, and depending on what you’re doing, there could be a lot of them. Bring some order to that chaos with this script, which can list all the text anchors in your document, help you navigate to them, and show you what they were used for (Figure 13).

Dialog box Text Anchors (6) with columns for text anchor, source type, and source name. Underneath dialog box is screen shot of page with the names of the text anchors superimposed in yellow text frames.

Figure 13. You can even use the Manage Text Anchors script to generate bright temporary frames to flag their use visually.

Title Case

Editors rejoice! This script replaces InDesign’s almost useless Title Case command, by allowing you to apply correct capitalization to titles (Figure 14). The script works with a text file of “exception” words that won’t get capitalized, so you can customize it for your needs. It also includes six modes for choosing which text gets processed, (such as all text in quotes or all text in italics) so you can fix the capitalization in an entire bibliography at once.

Before: “Draw the 2D objects” and after: "Draw the 2D Objects"

Figure 14. The Title Case script offers a better way to convert capitalization in headlines and titles.

Select a Line

If you’ve ever had to follow editorial directions like, “Insert this text at the end of line 13 in column 2,” you’re going to like this script. It allows you to jump immediately to a line of text a certain number of lines up or down from your cursor (Figure 15).

Dialog box "Go to line" shows field for line number and buttons: from top of page, down from insertion point, from bottom of page, up from insertion point.

Figure 15. Make your way through correcting a huge and complex book.

Export Book Documents

If you’re using Book files to tame a gargantuan project, you will appreciate having more control over export of those pages and files. This script (Figure 16) lets you export PDFs of individual INDD files in your Book, and it lets you export individual pages and ranges of pages.

Dialog box with title of book and "export chapters to PDF" shows two INDD files in book selected with buttons for select all, deselect all, invert selection, OK, cancel. Radio buttons for print pdf and interactive pdf. Option to export documents as whole documents, as individual pages, or individual sections (use section markers in file names/use section prefixes in file names) and field to specify output folder.

Figure 16. This script offers a better way to control exporting pages, chapters, or a full InDesign Book.

Collect Hyphenated Words

For generations, copy editors have had complicated relationships with words hyphenated by computer. I know a few who sure would have appreciated how this script (Figure 17) gives you a report on every hyphen inserted into the text flow and where you can find (and maybe correct) it.

But wait—it gets better! Mark up the hyphenation report with simple codes, run a second script (Implement Corrections in Document or Exception List), and you can sit back and watch as InDesign automatically makes your corrections.

Dialog box "hyphenation checker" with selection for output and separator; check boxes for include hyphenated words, use list from text file (greyed out), sort list (checked), filter out the exception list. Field for columns in document output (2). Checkboxes for include details in document output (checked) and delete duplicates in document output.

Figure 17. This script lists all the words that InDesign has hyphenated.

Remove Spurious White Space

Here’s a simple one. Do you have text with multiple tabs and returns? Click the script, and blast them all to oblivion. (And c’mon—where else are you going to find a script whose name includes the word spurious?)

Write Pasted and Embedded Images to Disk

When you cut and paste images into your INDD instead of linking or embedding them, one major problem emerges: InDesign won’t show you any information about the image in the Links panel. This script will ask you to tell it where to save the files, then specify a file format (Figure 18). Access to information restored (Figure 19)!

dialog box "save pasted images" shows selection for export format (options: EPS (selected), JPEG, PNG); checkbox for create links (checked)

Figure 18. You can make your pasted image a linked PNG, JPEG, or, if you’re feeling nostalgic, EPS.

 

Image in figure 18 behind links panel showing lined file TEST_0.PNG with all metadata below

Figure 19. Presto! Your image metadata and resolution is restored.

Highlight Word and Letter Spacing

You can use some of Peter Kahrel’s scripts as infrared binoculars (of sorts) to see type attributes that would otherwise be invisible to you. Want to quickly see paragraphs where you’ve locally tweaked the justification settings? Run this script, which uses conditional text to color-code text affected by glyph scaling, horizontal scaling, letterspacing, tracking, and word spacing (Figure 20).

The Highlight No Break script works the same way, highlighting any text to which No Break has been applied.

conditional text panel shows conditions defined: unconditional, glyph_scaling, horizontal_scaling, letter_spacing, tracking, word_spacing (checked). Document text shows one paragraph highlighted in green (word spacing), one in orange (glyph scaling)

Figure 20. This script will add (nonprinting) color flags to paragraphs whose spacing deviates from the style.

Change Custom Text Variables

Text variables are such powerful tools, and this script makes them even better with an improved user interface for updating them without having to click through multiple dialog boxes one at a time (Figure 21).

dialog box "update text variables" shows fields for 19 text variables and their values in example document

Figure 21. Run this script to update your text variables all at once.

Sort Tables

This script does—well, exactly what you expect it to (Figure 22). You can sort the content of an entire table or a selection of rows according to multiple criteria, with options to define the sorting order, ignore header and footer rows, and set the direction (ascending or descending).

Dialog box table sort with fields for sort order: first sort on column (2); checkbox for numeric; then on column (5); checkbox for numeric; then on column (blank); checkbox for numeric. Fields for number of header rows (1), number of footer rows (0); radio buttons for direction: ascending or descending (selected); checkboxes for ignore case (selected), format text.

Figure 22. The interface of the Table Sort script allows you to apply sophisticated sorting to tabular data.

Set/Find a Bookmark

You’re slogging through a huge document, and you need to check something on another page. The first of these two scripts invisibly marks this location. Running the second script brings you back to that exact location from anywhere else in the document.

“I Always Had Fun Writing Scripts”
Two men, laughing and smiling, side by side looking at computer screen

Peter Kahrel, right, checks out some code with Kris Coppieters of Rorohiko Workflow Resources at a CreativePro conference of yore.

Peter Kahrel’s scripts seem tailor-made for those working with multiple files, long documents, InDesign Book files, citations, and indexes.

That’s no accident. They were!

Kahrel, who lives in Spain by way of Britain and his native Amsterdam, comes to the InDesign world through many years of typesetting, editing, and paginating books, mainly for university presses. With a Ph.D. in linguistics and experience in programming, going back to 1980, he easily took to scripting InDesign from the program’s early versions.

“Much of typesetting is very dreary work,” Kahrel says, a hint of mischief in his voice. “And I always had fun writing scripts, which also improved my work as a typesetter. Because you work quicker, the tedium gets out of the way so you can concentrate on things that are more interesting.”

He soon accumulated a lot of scripts, and “I thought they might be useful for other people as well,” he says. By 2007, he had made them available on his website.

For Kahrel, those scripts made possible the seemingly impossible, like a three-volume, 1,300-page book with sidenotes. One by one, his script pulled each sidenote from the text flow, drew a text frame in the margin, pasted the sidenote, and applied a style to it.

This code, which took all of a couple of hours to write and 15 minutes to run, became the Dynamic Sidenotes scripts that Kahrel has made available for all.

Time Is Money

Kahrel no longer uses his own scripts regularly. He now works with Typefi, a global software developer whose product, written in JavaScript, automatically paginates heavily templated books and other documents with InDesign Server. The world of per-page book typesetting became too cutthroat, he says.

For those still in that world, he says that using time-saving automation like scripts is essential.

“With rates falling, it becomes more important that you [work] efficiently and quickly,” he says. “Otherwise, you make no money.”

And moreover, and more importantly, “If you get your script right, [your work is] flawless,” he says.

He does acknowledge that even some power users resist the idea of using scripts, much less writing them.

In the end, it’s their loss.

“All I can say to those people is good luck,” Kahrel says with a smile.

Rewarding the Value of Scripts

Peter Kahrel is only one of a tight-knit world of kind and smart InDesign scripters who are unstinting with all aspects of their coding. For new users who are struggling with an error, these scripting veterans help with debugging via posts on social media or web forums.

When these freely distributed scripts become enormously helpful to you in your own journey as a designer—and help contribute to your professional bottom line—consider dropping a donation. It’s good for the InDesign community, and it’s the right thing to do.

Interested in Scripting? Peter Wrote the Book.

Did these scripts jump-start your imagination? Scripting is challenging, exacting, and, for many people, an unexpected source of fun. CreativePro Network has published the second edition of Peter Kahrel’s book JavaScript for InDesign: An InDesign Secrets Guide, available as an ebook or in print.

More Resources To Master InDesign

The InDesign Conference is coming to a screen near you—hosted entirely online, December 9–12, 2025.

Join the world’s most knowledgeable InDesign experts as they share their wisdom, tips, and techniques for building documents of every size and format.

LEARN MORE

Members get a special discount on registration! Sign up today.
Bookmark
Please login to bookmark Close

Not a member yet?

Get unlimited access to articles and member-only resources with a CreativePro membership.

Become a Member

Comments (1)

Leave a Reply

Your email address will not be published. Required fields are marked *

  1. WB Design

    I am deeply indebted to Peter for generously donating his efforts and skill to the larger world, and to CreativePro for hosting his huge archive. I don’t use Peter’s scripts every day, but when I do I’m always amazed by their elegance and craft.