2011年5月19日 星期四

Adobe Acrobat Javascript Example Codes

用 JavaScript 的方式語法較簡單。

修改 UI

利用 app。如 app.addMenuItem

重要的參數包括:

  1. cName: The language-independent name of the menu item. This name can be used by other methods (for example, hideMenuItem) to access the menu item.
  2. cUser: (optional) The user string (language-dependent name) to display as the menu item name. If cUser is not specified, cName is used.
  3. cParent: The name of the parent menu item. Its submenu will have the new menu item added to it. If cParent has no submenu, an exception is thrown.
  4. nPos: (optional) The position within the submenu to locate the new menu item. The default behavior is to append to the end of the submenu. Specifying nPos as 0 adds the menu to the top of the submenu.
  5. cExec: An expression string to evaluate when the menu item is selected by the user.

quads 應用

quads 回傳的內容為 4 組 (x, y) 的座標內容。舉例來說,
quads: [[43],[756],[78],[756],[43],[745],[78],[745]],
代表的是如下圖的座標:

image

的座標。

下面是動態建立一個 quads 與 Annotation 的範例:

var quads1=this.getPageNthWordQuads(p, startIndex);
var quads2=this.getPageNthWordQuads(p, endIndex);
var quads=[[quads1[0][0], quads1[0][1], quads2[0][2], quads2[0][3], quads1[0][4], quads1[0][5], quads2[0][6], quads2[0][7]]];
var annot = this.addAnnot({page: p, type: "Highlight",
                                      quads: quads, author: annotator
                                     });

上面的程式碼要注意換行的情況。

Resources

沒有留言: