AppleScript名:PDFの指定ページを削除 v3(PDFDocument経由でアクセス) |
— Modified 2017-08-19 by Takaaki Naganoya –Original By Shane Stanley use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "Quartz" –http://piyocast.com/as/archives/4781 property |NSURL| : a reference to current application’s |NSURL| property PDFDocument : a reference to current application’s PDFDocument set inFile to (choose file of type {"pdf"} with prompt "Choose your PDF files:") set targPage to 7 set pRes to removeSpecificPageInPDF(inFile, targPage) of me on removeSpecificPageInPDF(inFileAlias, targPageNum) set inNSURL to |NSURL|’s fileURLWithPath:(POSIX path of inFileAlias) set theDoc to PDFDocument’s alloc()’s initWithURL:inNSURL set pRes to theDoc’s pageCount() if absNum(targPageNum) of me > pRes or targPageNum = 0 then error "PDF Page Range error. This PDF document has " & (pRes as string) & " pages. But you pointed " & (targPageNum as string) & " page from your script. " & return & " (available abs range :1…" & (pRes as string) & ", relative range: -1…-" & (pRes as string) & ")" end if –Allow Relative Page Num ( -1 = the last page) if targPageNum ≤ 0 then set targPageNum to pRes + targPageNum + 1 end if theDoc’s removePageAtIndex:(targPageNum – 1) –Overwrite Exsiting PDF set aRes to (theDoc’s writeToURL:inNSURL) as boolean return aRes end removeSpecificPageInPDF on absNum(q) if q is less than 0 then set q to –q return q end absNum |
More from my site
(Visited 19 times, 1 visits today)