- Illustratorスクリプトメモ
- 参照数: 2418
JavaScriptです。
配置するPDFファイルのページ数の取得は、
-
PDFファイルのページ数を知りたい - 手抜きLab@DTPの現場
で公開されているコードを使用すると取得できるのですが、FileMakerProから出力したPDFファイルは取得できません。問題のPDFを開いてみると、
<< /Type /Pages /Count 19
ページ数はこんな風に書いてあるようです。この部分は複数書かれている場合があるので、PDFから探して一番大きい値を取得する必要があります。
function GetPageLength (obj) { var tg = /<<\/Count\s(\d+)/; var count = /<<\/Type\/Page\/Parent/; var count_2 = /\/Type\s\/Page\s/; var count_3 = /\/StructParents\s\d+.*\/Type\/Page>>/; var count_fmp = /\/Count\s([0-9]+)/; var tg2 = /<<\/Linearized\s.+\/N\s(\d+)\/T\s.+>>/; //add target "Linearized PDF Document Structure" var len = 0; var len2 = 0; if (obj.open('r')) { while (!obj.eof) { wd = obj.readln(); if (tg.test(wd)) return RegExp.$1 - 0; if (tg2.test(wd)) return RegExp.$1 - 0; if (count.test(wd)) len++; if (count_2.test(wd)) len++; if (count_3.test(wd)) len++; if (count_fmp.test(wd)) { len2 = Number(wd.match(count_fmp)[1]); if (len < len2) { len = len2; } }; } } if (len > 0) return len; return null; }
というわけでFileMaker用のマッチを追加したのがこちら。