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

Repositioning index

New Here ,
Apr 18, 2022 Apr 18, 2022

Copy link to clipboard

Copied

Hello everyone,

 

The pdf generated seems to reposition the TOC and move from the frame where it is attached on the template used to create the pdf.

 

Don´t really know whats the cause of this, we attach the TOC to the correct frame and it seems to just move it. The weirdest point is that if the TOC is big enough to need 2 pages, the second page is well and just reposition the first one.

 

Thanks for the help

TOPICS
Scripting

Views

294

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 ,
Apr 18, 2022 Apr 18, 2022

Copy link to clipboard

Copied

I can help here, I believe.

 

When you create a Table of Contents, it creates a hypertext document to place in your InDesign file. Think of hypertext information as additional data that tells InDesign that this is more than plain ol' text.

 

If you don't have your Text tool selected and a cursor placed in the text frame you want to put it in, you're always going to get a new ToC document in what InDesign calls the place gun. You can place the cursor in your existing text frame and plug in your ToC text, but if you do that you can break the hypertext content intrinsic to your created ToC and will be placing nothing more than the plain ol' text characters it includes into your InDesign file. Which makes replacing/updating the info in your complex InDesign document(s) a real pain.

 

So it may be a bother, but I'd actually recommend you place your generated ToC hypertext document directly into InDesign, rather than try to insert it into an existing text frame. This may not be the answer you were looking for, but I believe it will help you in the long run.

 

Randy

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 ,
Apr 19, 2022 Apr 19, 2022

Copy link to clipboard

Copied

Hello Randy,

 

One important thing that forgot to comment before, I'm using InDesign server, so we don't have interface, tried your recommendation on the script not setting the TOC to the frame but still reposition incorrectly.

 

In this case, like we are using indesign server the toc is generated and we just try to put it on the frame with correct positioning. I am not sure if this information is helping or if something more is needed in each case please comment and I'll try to bring all the info possible.

 

Thank you for the recommendation and information, I'm still learning so all info is appreciated.

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 ,
Apr 19, 2022 Apr 19, 2022

Copy link to clipboard

Copied

One thing you can do is position ruler guides to frame the area where you'd like your ToC to be. Then all you'd need to do is click-drag your place gun to fill the framed area for your ToC.

 

You can even set things up in advance by building custom parent pages for your ToC and putting them in your book templates to make it a drag'n'drop operation.

 

Hope this helps,

 

Randy

 

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 ,
Apr 19, 2022 Apr 19, 2022

Copy link to clipboard

Copied

@Randy Hagan -- There is no place gun InDesign Server

 

@default05v6kf194i27 -- Here's a workaround that works for me.

- In your template, name the TOC frame (or whichever frame you want to TOC to appear in) on the Layers panel so that a script can find that frame. Let's call it 'TOC'

- When your script creates the TOC, check whether its parent textframe is the designated frame. If it isn't, move it there:

 

 

var target = tocDocument.pages[0].textFrames.item ('TOC');
var tocStory = tocDocument.createTOC (. . .);
if (tocStory.textContainers[0] != target) {
  tocStory.move (LocationOptions.AT_BEGINNING, target);
}

 

 

P.

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 ,
Apr 25, 2022 Apr 25, 2022

Copy link to clipboard

Copied

Thanks for the reply, we tried it but seems like doesn't solve the problems. I'll explain what happened, the createToc returns a Story object but when try to access the textContainers that should return an array of textFrames or textPaths seems can't access to it and causes an error of undefined. After that just comment the if and did the move function but again appears that the object hasn't that function.

 

Seeing the documentation the Story shouldn't have any problem with the function or the textContainers property but caused an error. We checked that the createToc returns a Story object but seems like the property of textContainers and the funcion move() didn't add to it correctly.

 

I'll add more information about the problem, checking the geometric bounds of the textFrame of the template they already appears moved when added but the indt file has the correct bounderies on the textFrames.

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 ,
Apr 25, 2022 Apr 25, 2022

Copy link to clipboard

Copied

Please show the code you use. Just the relevant part.

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 ,
Apr 26, 2022 Apr 26, 2022

Copy link to clipboard

Copied

This should be the relevant code:

 

var tocStory = styleDoc.createTOC(styleToc,true,myBook);
app.open(templateFile);
styleDoc.loadMasters(File(templateFile));
styleDoc.recompose();

styleDoc.pages.item(0).appliedMaster=styleDoc.masterSpreads.itemByName(masterSpredName);
var styleDoc = overrideMaestra(styleDoc,styleDoc.pages.item(0), masterSpredName) //override every page masterSpread.pages.item(i).textFrames.item(ov).override(page);

styleDoc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.millimeters;
styleDoc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.millimeters;
styleDoc.viewPreferences.rulerOrigin = RulerOrigin.pageOrigin;
   
styleDoc.pages.item(0).layoutRule = LayoutRuleOptions.OFF;
styleDoc.recompose();

if (tocStory.textContainers[0] != styleDoc.pages.item(0).textFrames.itemByName("TOC")) {
    tocStory.move(LocationOptions.AT_BEGINNING, styleDoc.pages.item(0).textFrames.itemByName("TOC"));
}

 

I also tried textFrames[0] instead of textContainers[0] and cause the same undefined error. After that, tried to just call the move function without the conditional and the error showed was that it wasn't a valid 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
Community Expert ,
Apr 26, 2022 Apr 26, 2022

Copy link to clipboard

Copied

You probably lose the reference to the TOC story because of everything you do to the document after you generate the TOC. So the first thing I would try is to move the TOC generation after everything you do to the document. So:

styleDoc.recompose();
var tocStory = styleDoc.createTOC(styleToc,true,myBook);
if (tocStory.textContainers[0] != styleDoc. . .

P.

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 ,
Apr 26, 2022 Apr 26, 2022

Copy link to clipboard

Copied

Hello,

 

I tried to use them just after

styleDoc.pages.item(0).appliedMaster

and at the end like you suggested and in both cases the same errors happen. TextContainers[0] undefined and move like not a function.

 

I'm using the sdk 16.1 version so I look the next documentation to see what is viable or not: https://www.indesignjs.de/extendscriptAPI/indesign-latest/index.html#Document.html. On it the solution you propose seems correct but when tried to use it appears the errors explained above

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 ,
Apr 26, 2022 Apr 26, 2022

Copy link to clipboard

Copied

LATEST

I suddenly remember that createTOC creates an array of toc stories (even if there;'s just one), so the code should be

var tocStory = styleDoc.createTOC(styleToc,true,myBook)[0];

Note the [0] at the end. Also, you want to include overset text. Not sure if that's an issue in your workflow, but better include it:

var tocStory = styleDoc.createTOC(styleToc,true,myBook, undefined, true)[0];

The last 'true' includes overset text.

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