【问题标题】:Is there a way to tell which page number the textframe exists in?有没有办法判断文本框存在于哪个页码?
【发布时间】:2020-03-02 08:59:21
【问题描述】:

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

【问题讨论】:

    标签: scripting adobe-indesign extendscript indesign-server


    【解决方案1】:

    有没有办法判断文本框存在于哪个页码?

    1. 是的,每个TextFrame 类都有一个parentPage 属性,该属性返回对文本框所在Page 的引用。

    2. 每个Page 类都有一个name 属性,它本质上返回一个页码字符串

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

    var doc = app.activeDocument;
    var firstTextFramesPageNumber = doc.textFrames[0].parentPage.name;
    
    $.writeln(firstTextFramesPageNumber)
    

    我想知道是否有什么方法可以让我理解下一个文本框在下一页中,以避免计算时出现负值。

    为此,您需要:

    1. 确定文本框是否有关联的下一个文本框。您可以通过使用TextFrame 类的nextTextFrame 属性来实现此目的。它会:

      • 如果没有关联的下一个文本框,则返回 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('--------------')
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-05-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多