有没有办法告诉文本框存在于哪个页码?

Is there a way to tell which page number the textframe exists in?

我正在尝试找出特定文本是否存在并完全适合文本框架,以及文本何时流向下一个文本框架,然后在计算下一框架的坐标(基线)时增加大小现有框架并尝试适合文本但是当文本框架在下一页时基线它给了我一个负值所以我想知道是否有任何方法我可以理解下一个文本框架在下一页,以免计算时出现负值。

Is there a way to tell which page number the textframe exists in?

  1. 是的,每个 TextFrame class 都有一个 parentPage 属性 那 returns 对 Page 的引用文本框已打开。

  2. 每个Pageclass都有一个name属性本质上是returns一个页码字符串

因此,以下代码片段将文档第一个文本框所在的页码记录到控制台。

var doc = app.activeDocument;
var firstTextFramesPageNumber = doc.textFrames[0].parentPage.name;

$.writeln(firstTextFramesPageNumber)

I would like to know if there is any way I could understand that the next text frame is in next page so as to avoid negative value while calculating.

为此,您需要:

  1. 确定文本框是否有关联的下一个文本框。您可以利用 TextFrame class 的 nextTextFrame 属性 来实现这一点。它会:

    • Return null 如果没有关联的下一个文本框。
    • 或者,在存在关联的下一个文本框时引用下一个文本框。
  2. 一旦您知道有关联的下一个文本框架,您可以检查 parentPage.name 以获取引用的下一个文本框架以获取其页码。

  3. 要检查文本框架及其关联的下一个文本框架是否在同一页上,请使用 === 相等运算符进行检查。


演示要点

下面是一个有点做作的示例要点。它遍历文档中的所有文本框并将以下内容记录到控制台:

  • 当前文本框所在的页码。
  • 当前文本框是否有关联的下一个文本框。
  • 当当前文本确实有关联的下一个文本框时,它会告诉您它在哪个页码上。
#target indesign

var doc = app.activeDocument;

var textFrames = doc.textFrames;

for (var i = 0, max = textFrames.length; i < max; i++) {
   var currentTextFrame = textFrames[i];

   // 1. Get the current text frames page number
   var currentTextFramePageNumber = currentTextFrame.parentPage.name

   $.writeln('The current text frame is on page ' + currentTextFramePageNumber)

   // 2. Get the current text frames associated next text frame.
   var hasNextTextFrame = currentTextFrame.nextTextFrame;


   if (hasNextTextFrame) {     
     // 3. Let's get the page number of the associated next text frame?
     var nextTextFramePageNumber = currentTextFrame.nextTextFrame.parentPage.name

     // 4. Is the associated next text frame on the same page number as the current text frame?
     if (currentTextFramePageNumber === nextTextFramePageNumber) {
      $.writeln('This text frame DOES have a next text frame. It\'s also on on page '
          + nextTextFramePageNumber)
     } else {
      $.writeln('This text frame DOES have a next text frame. However it\'s on a different page, it\'s on page '
          + nextTextFramePageNumber) 
     }

   } else {
     $.writeln('This text frame DOES NOT have a next text frame.')
   }

   $.writeln('--------------')
}