• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
1

create TOC javascript for indesign book

Community Beginner ,
Nov 11, 2009 Nov 11, 2009

Copy link to clipboard

Copied

Hi friends,

i am new to indesign javascript. i want to create a javascript for TOC indesign book using paragrph style

could anyone help me. i am strugling long time.

TOPICS
Scripting

Views

5.4K

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
Community Expert ,
Nov 11, 2009 Nov 11, 2009

Copy link to clipboard

Copied

That sounds like the regular TOC function (it also works on Books).

Do you want to have a script that does the same without using the built-in TOC function (which is ... well, not really necessary, is it?), or do you want to use the TOC function through Javascript? (See in the ESTK Help: TOCStyle, TOCStyleEntry for the definitions, and Document.createTOC to actually create it.)

Votes

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
Community Beginner ,
Nov 11, 2009 Nov 11, 2009

Copy link to clipboard

Copied

Thank you very much Jongware for your reply. Actualy i tried predefined function createTOC(). but it did'nt wotk for me.

i want to do in without buildin function .

Votes

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
Guide ,
Nov 11, 2009 Nov 11, 2009

Copy link to clipboard

Copied

Maybe IndexMatic could help you in this task.

You can download the script from this page:

http://www.indiscripts.com/post/2009/10/indiscripts-temporary-archives

@+

Marc

Votes

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
Community Expert ,
Nov 11, 2009 Nov 11, 2009

Copy link to clipboard

Copied

"It didn't work for me" doesn't work for me. Always, always, always, state why it doesn't work for you.

Did you try to use it, but could not get it to work?

Or, do you need to do something special that the built-in function does not do?

It should not be extremely hard to make a javascript version that does (roughly) the same. You could try something like this:

  1. For every paragraph style you want to include (most likely all sorts of headings),
  2. Search for all occurrences, and store the text, its page number, and (important!) its story offset in an array.
  3. You need the text because that's what will appear in the TOC.
  4. You need the page number because, well, that's what the TOC is for 🙂
  5. Most important: you need the story offset so you can reconstitute the original order of the headings. You can only search for one level of heading at a time, so without sorting, you would get "Heading 1 -- Heading 1 -- Heading 1 -- Heading 2 -- Heading 2 -- Heading 2" (etc.)
  6. When you have gathered all of the information for your entire book, sort on story offset. (I forgot, it's for a Book, right? You need to store a document id as well, so you can sort throughout multiple documents.) (See Ed.)
  7. Then write out every text in the right order, followed by its page number.

The IndexMatic script that Marc points out should already contains lots of the logic described here -- esp. searching and storing page numbers.

[Ed.] Thinking about it, a Book (multiple documents) should *not* cause any problems, and you don't need to know in which document some text was found. Simply sort the paragraphs on their page number; only when these are the same for more than one paragraph, sort just these on their Story Offset. Logically, there should not be two headers with the same page number in two different documents.

Votes

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
Community Beginner ,
Nov 14, 2009 Nov 14, 2009

Copy link to clipboard

Copied

Hi Jongware,

with your valuable help i created TOC using predefined function. i defined the TOC style created from Layout---->Table of contenet--->TOCStyle.

but i want to create through script. can u tell me the syntax.

Votes

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
Community Expert ,
Nov 14, 2009 Nov 14, 2009

Copy link to clipboard

Copied

LATEST

The syntax is

Array of Story createTOC (using: TOCStyle[, replacing: bool=false][, fromBook: Book][, placePoint: Array of Measurement Unit (Number or String)=any][, includeOverset: bool=false][, destinationLayer: Layer])
Creates a table of contents.

ParameterTypeDescription
usingTOCStyleThe TOC style to use to define the content, title, and format of the table of contents.
replacingboolIf true, replaces the existing TOC. (Optional) (default: false) (Optional)
fromBookBookThe book whose documents to include in the TOC. (Optional)
placePointArray of Measurement Unit (Number or String)=anyThe point at which to place the TOC story, specified as page coordinates in the format [x, y]. (Optional)
includeOversetboolIf true, includes overset text TOC entries in the TOC. (Optional) (default: false) (Optional)
destinationLayerLayerThe layer on which to place the TOC. (Optional)

-- and I copied it from the ESTK Help, which is, really, the best place to look up the syntax for any JS command ...

Votes

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 ,
Nov 11, 2009 Nov 11, 2009

Copy link to clipboard

Copied

I am wondering if you need a script. The TOC feature in InDesign CS4 seems pretty easy to use. I think it takes a bit of understanding how the TOC feature works.

I'm relatively new using ID CS4, however I use the built-in feasture all the time. Let me know if you use the TOC feature (in the Layou menu).

RPP

Votes

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
Community Beginner ,
Nov 13, 2009 Nov 13, 2009

Copy link to clipboard

Copied

can you tell me how to use. i tried buildin createTOC(). i am getting confused with parameter. it's worked for me . but TOC placed when i go to Layout-->

table of contents  and if i click the TOC style-->paragraph style. The TOC place into the 4th page. why it's not working in this code i don't know.

here i place the code.

function toc() {
//    Set MyTOCStyle = myDoc.TOCStyles.Add
    //Set myPage = myDocument.Pages.Item(1)
    var myTOCStyle = myDocument.tocStyles.itemByName("TOC");
    var myTocPage = myDocument.pages.add(LocationOptions.AT_END);
    var myBounds = myGetBounds(myDocument, myTocPage);
    var myX1 = myBounds[1];
    var myY1 = myBounds[0];
    var myStory = myDocument.createTOC(myTOCStyle, true, undefined, [myX1, myY1]);
    var myFrame = myStory.textContainers[0];

}

toc();

Votes

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