PDFpenでマルチページTIFFをページごとに分解する
MVPenテクノロジーズのデジタルペン、「MVPen」のMac版を入手したところ、出力されるデータが「マルチページTIFF」などという、存在自体は知っていたものの直接見たことなどなかったシロモノで、(Preview.appでオープンできるものの)取扱いが少々めんどくさい形式でした。
ページごとに1つのファイルになっていれば、Keynoteに貼り込む場合でも手軽に扱うことができるので、分割して他の画像フォーマットに変換できないかと調べてみたところ……PDF編集用ソフト「PDFpen」でマルチページTIFFを扱えることが判明(他に、ImageMagickなどでも変換できるもよう。Mac OS X標準搭載のsipsあたりで変換できるとベストなのですが)。

さっそく、PDFpenでオープンしたマルチページTIFFを、各ページごとのPDFに変換するAppleScriptを作ってみました(所要時間15分)。実行前にPDFpenでマルチページTIFFをオープンしておく必要があります。実行すると、マルチページTIFFと同じ階層のフォルダに、子番号つきのPDFが書き出されます。

| スクリプト名:PDFpenでマルチページTIFFをページごとに分解する |
| tell application “PDFpen“ set docName to name of document 1 tell document docName set pCount to count pages set docPath to path end tell end tell set digitNum to length of (pCount as string) –ページ数の最大桁数をかぞえる set docMacPath to (POSIX file docPath) as string –ファイルパスをPOSIX pathからMacなパスの文字列に変換 set pFol to getParentFolderFromStringPath(docMacPath) of me –ドキュメントの親フォルダを求める set rootName to text 1 thru -6 of docName –ファイル名から拡張子を外す tell application “PDFpen“ repeat with i from 1 to pCount set newDoc to make new document copy page i of document docName to end of newDoc set savePath to pFol & rootName & “_“ & retZeroPaddingText(i, digitNum + 1) of me & “.pdf“ save newDoc in file savePath –ファイル保存 close document 1 –最前面の(新規に作成した)ドキュメントをクローズ end repeat end tell –テキストのパスから、ファイルの親フォルダを求める on getParentFolderFromStringPath(aPAth) set rPath to reverse of characters of aPAth set rtPath to rPath as string set aPos to offset of “:“ in rtPath set aLen to length of aPAth set aRes to text 1 thru (aLen - aPos + 1) of aPAth return aRes end getParentFolderFromStringPath –数値にゼロパディングしたテキストを返す on retZeroPaddingText(aNum, aLen) set tText to (”0000000000“ & aNum as text) set tCount to length of tText set resText to text (tCount - aLen + 1) thru tCount of tText return resText end retZeroPaddingText |
