xlogI125’s blog

パソコン作業を効率化したい

Acrobat JavaScript練習 上位レベルのしおりのページ番号と名前を表示

メモ

  • 上位レベルのしおりで分割するときのページの重複を避けるため、しおりのページ番号と名前を確認するためのスクリプト

使い捨てスクリプト

  • ページ番号は doc.bookmarkRoot.children[i].execute() としたときの doc.pageNum + 1 であると仮定する
  • 別の文書内のページに移動することは無いと仮定する
// Acrobat Standard DC (2022年6月頃), Windows 11
// JavaScript デバッガー の コンソール から実行
// 実行方法はテキストを範囲選択して Ctrl + Enter

(() => {

const srcFunc = 
(() => {
  /* 別の文書内のページに移動することは無いと仮定します */
  const doc = this;
  const bkm = doc.bookmarkRoot.children;

  console.show();
  console.clear();

  if (bkm == null) {
    console.println("しおり がありません。");
    return;
  }

  console.println(util.printf("%s\t, %s", "page", "name"));

  [...Array(bkm.length)].forEach(($null, i) => {
    doc.pageNum = 0;
    bkm[i].execute();
    console.println(util.printf("%4d\t, %s", doc.pageNum + 1, bkm[i].name));
  });

}).toString().replace(/\r\n/g, "");


const src = util.printf("%s%s%s", "(", srcFunc, ")();");

app.addMenuItem({
  cName: 'MyViewBookmark', 
  cUser: '上位レベルのしおりのページ番号と名前を表示', 
  cParent: 'View', 
  nPos: 0, 
  cExec: src, 
  cEnable: 'event.rc = (event.target != null);', 
  cMarked: 'event.rc = false;', 
  bPrepend: true
});

})();