AppleScript名:ASOCでPDFをページごとに分解する v3 |
— Created 2014-12-26 by Takaaki Naganoya — Modified 2015-09-26 by Takaaki Naganoya — Modified 2015-10-01 by Takaaki Naganoya — 2015 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" –use framework "Quartz" use framework "QuartzCore" set aHFSPath to (choose file of type {"com.adobe.pdf"} with prompt "ページごとに分解するPDFを指定してください") set aPOSIX to POSIX path of aHFSPath set aURL to (current application’s |NSURL|’s fileURLWithPath:aPOSIX) set aPOSIXpath to POSIX path of aHFSPath —書き出し先パスをPOSIX pathで用意しておく(あとで加工) set aPDFdoc to current application’s PDFDocument’s alloc()’s initWithURL:aURL set pCount to aPDFdoc’s pageCount() –PDFをページごとに分割してファイル書き出し repeat with i from 0 to (pCount – 1) set thisPage to (aPDFdoc’s pageAtIndex:(i)) set thisDoc to (current application’s PDFDocument’s alloc()’s initWithData:(thisPage’s dataRepresentation())) set outPath to addString_beforeExtensionIn_("_" & (i + 1) as string, aPOSIXpath) (thisDoc’s writeToFile:outPath) –書き出し end repeat –ファイルパス(POSIX path)に対して、文字列(枝番)を追加。拡張子はそのまま on addString:extraString beforeExtensionIn:aPath set pathString to current application’s NSString’s stringWithString:aPath set theExtension to pathString’s pathExtension() set thePathNoExt to pathString’s stringByDeletingPathExtension() set newPath to (thePathNoExt’s stringByAppendingString:extraString)’s stringByAppendingPathExtension:theExtension return newPath as string end addString:beforeExtensionIn: |
More from my site
(Visited 23 times, 1 visits today)