Extract Pages is a great InDesign script to divide an existing InDesign document into separate pages or groups of pages.

Each page, or group of pages, is saved as a separate file.

Until version 1.3, the filenames of these newly created files followed a basic pattern that could not be modified by the user.

Starting with version 1.3, the filename pattern can be modified by the user. Some very powerful building blocks allow for a wide variety of filename patterns to be specified easily.

For ease of use, a useful “default” filename pattern is also available for users for whom this is sufficient.

This article will describe how to use the advanced filenaming feature of Extract Pages.
Extract Pages Screenshot

Basic Custom File Naming

To use a custom filenaming scheme, select the “Custom” radio button, and type the filenaming scheme you would like to use.

For instance, if you type:

Ace Food

and choose to save each page of a 10-page file as separate files, the file names will become:

Ace Food.indd

Ace Food-1.indd

Ace Food-2.indd


Ace Food-9.indd

Overwriting Existing Files

Extract Pages no longer overwrites existing files in the same folder that have the same name.

So if a file called Ace Foods.indd already exists in the selected folder, Extract Pages will automatically modify the name to something that does not exist already: Ace Foods-1.indd.

If, as per the previous example, Ace Foods-1.indd through Ace Foods-9.indd are all used, the first file will be called Ace Foods-10.indd.

The point is that Extract Pages will find a new name for all files, and will no longer overwrite existing files. So if needed, first manually delete all existing files from the selected folder.

Advanced Custom File Naming

In addition to simple custom file names, any of the following special codes can be inserted one or more times into the Custom filename field to create advance naming schemes.

First Page <fp> 

The <fp> code will be replaced, for each extracted file, with the name of the first page of that file. For example, typing the following into the Custom field (using the 10-page Ace Foods example mentioned previously):

Ace Foods Page <fp>

will result in the following files:

Ace Foods Page 1.indd

Ace Foods Page 2.indd


Ace Foods Page 10.indd

Last Page <lp>

As with the <fp> code, the <lp> code will be replaced with the name of the last page of the extracted file. For example, if we were to split the Ace Food file into two (pages 1-5, and pages 6-10), typing the following in the Custom field:

Ace Foods Pages <fp>-<lp>

would result in the following 2 files:

Ace Foods Pages 1-5.indd

Ace Foods Pages 6-10.indd

File Name <fn>

The <fn> code just inserts the full name of the original file.

So, if the original file was called Ace Foods.indd, and it is divided into 2 sections as above, typing

<fn> Pages <fp>-<lp>

would again result in:

Ace Foods Pages 1-5.indd

Ace Foods Pages 6-10.indd

Counter #

The hash sign # can be used as a placeholder for a simple counter. For the first extracted file, it will have a value of 1. For the second, 2, and so on.

Multiple ### can also be used to pad the number with leading zeros. So ### will be replaced with 001 for the first file and 002 for the second, etc.

For example, typing the following into the Custom field

## Ace Foods

will result in

01 Ace Foods.indd

02 Ace Foods.indd

… and so on for each file created.

Conditional Text [ ]

Use square brackets [ ] to mark text as conditional.

Conditional text will only be used if the extracted file contains more than 1 page.

This is useful for sorting out singular/plural issues.

For example, if Ace Foods.indd contains 10 pages, and we want to divide it into 3 files: pages 1-3, page 4, and pages 5-10, we could type the following into the Custom field:

### <fn> Page[s] <fp> [through <lp>]

This would result in the following 3 files:

001 Ace Foods Pages 1 through 3.indd

002 Ace Foods Page 4.indd

003 Ace Foods Pages 5 through 10.indd

Because the 002 file has only a single page (page 4), the “s” after the word “Page” is omitted, as is the entire phrase “through <lp>”, since these were placed inside square brackets.

Section Marker <sm>

Use the <sm> code to insert the contents of the first section marker of the extracted file.

Paragraph Style <p:styleName>

Here’s where things start getting really powerful!

What the <p:styleName> tag does, is search each extracted file for the paragraph style specified (replace ‘styleName’ with the name of the desired paragraph style).

The text of the first such paragraph that is found in the extracted file will be inserted where the tag is.

Note: Any characters in the paragraph that are invalid for use as part of a filename will be stripped out of the result.

For example, let’s say we are preparing business cards for the 3 employees of the Ace Food company. We have an InDesign file with 3 pages of cards, one per employee (Mark Smith, Sue Lee, and Joe Levy).

buscardThe cards are set up in InDesign so that the employee name has the paragraph style “NameLine” applied to it in each of the three cards.

We now want to split this InDesign file into 3 smaller files, one file per business card, and we want the name of each file to be the name of the employee whose business card it is.

In such a case, typing the following in the Custom field


will result in the following 3 files:

Mark Smith.indd

Sue Lee.indd

Joe Levy.indd

Of course, it is possible to use multiple paragraph styles as well.

If, for example, we also want to include the employee’s role (which appears on each business card, and has the paragraph style “JobLine” applied to it), we could type:

<p:NameLine> <p:JobLine>

and the 3 files would then be called

Mark Smith CEO.indd

Sue Lee VP.indd

Joe Levy Food Specialist.indd

Character Style <c:styleName>

The <c:styleName> tag searches each extracted file for the character style specified (replace ‘styleName’ with the name of the desired character style).

For details, see the explanation for the <p:styleName> tag, above, as this tag is identical to that one, except that it uses character styles instead of paragraph styles.

Grep Search <g:searchName>

This is the last, and perhaps the most powerful, of all the building blocks so far.

GREP is an advanced InDesign feature, and if you are not familiar with GREP it is well worth reading up on! However, It is outside the scope of this page to go into the intricacies of GREP, so I am presuming that you are familiar with how to use GREP in InDesign to create a powerful filtered search phrase.

InDesign lets the user save GREP searches for reuse later. All that is needed is to click on the little disc icon in the GREP search window, and type in a name.

savegrepqueryThis is where the fun begins! You can use one or more GREP searches created previously in InDesign with Extract Pages’ custom naming feature to create a really powerful naming structure!

To do this, use the <g:searchName> tag, and replace “searchName” with the name of your saved GREP expression.

For instance, let’s say you have previously saved a GREP search that finds all underlined text that has the “Address” paragraph style applied to it (presuming you have an “Address” paragraph style in the document, of course). You saved this GREP and called it “FindUnderlinedAddress”.

To use this GREP search with Extract Pages, just type:


Extract Pages will search each extracted document for the first result of this GREP search, and use it as the file name for that extracted file.

Mix and Match

All the above codes can be used multiple times to create a complex file-naming scheme. For example, typing the following into the Custom field:

### <c:Title> <p:LastName> <g:FirstThreeLettersOfFirstName> <p:CompanyName> Page[s] <fp>[-<lp]

might result in the following file names (of course, this very much depends on the details of the results of the GREP search and contents of the paragraph and character styles for each file in question):

001 Mr Smith Mar Ace Foods Inc Pages 3-10.indd

002 Mrs Sue Lee Top Foods Page 9.indd

etc. etc.


If the custom naming scheme results in a filename that cannot be used by the operating system, Extract Pages will silently save that file with the default naming scheme.

Questions and Comments

Having difficulty putting together the right naming scheme? Post a comment below and we’ll be glad to try and help!