指定のTOCつきPDFからTOCを1Dリスト(1次元配列)で取得するAppleScriptです。各TOC項目のlabelの文字列を順次取得して1次元配列に出力します。
AppleScript名:PDFのしおり(TOC)の内容を取得する v2 |
— Created 2017-01-09 by Takaaki Naganoya — 2017 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "Quartz" property |NSURL| : a reference to current application’s |NSURL| property PDFDocument : a reference to current application’s PDFDocument property titleList : {} set my titleList to {} set aFile to POSIX path of (choose file of type {"com.adobe.pdf"}) set fileURL to |NSURL|’s fileURLWithPath:aFile set aPDFdoc to PDFDocument’s alloc()’s initWithURL:fileURL –TOCの読み込み set parentOL to aPDFdoc’s outlineRoot() –あらかじめTOCが存在していないとmissing valueになる if parentOL is equal to missing value then display dialog "本PDFにはTOCが添付されていないため、処理を終了します" with title "No TOC Error:" return end if getChilds(parentOL) of me return (my titleList) –再帰処理してみた on getChilds(parentOL) set outLineStr to parentOL’s label() set outLineCount to (parentOL’s numberOfChildren()) as number repeat with i from 0 to (outLineCount – 1) set anOut to (parentOL’s childAtIndex:i) set tmpOut to (anOut’s label()) as string set the end of my titleList to tmpOut set tmpChild to (anOut’s numberOfChildren()) as integer if tmpChild is not equal to 0 then getChilds(anOut) of me end if end repeat end getChilds |
More from my site
(Visited 73 times, 1 visits today)