AppleScript名:ASOCでPDFを回転させて保存 v2 |
— Created 2015-10-20 by Takaaki Naganoya — Modified 2016-07-01 by Takaaki Naganoya–複数回PDFに回転処理を行った場合の挙動を改善 — 2015 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "QuartzCore" set aPath to POSIX path of (choose file of type {"com.adobe.pdf"} with prompt "Select PDF") set newFile to POSIX path of (choose file name) set pdfRes to rotatePDFandSaveAt(aPath, newFile, 90) of me –oldPath and newPath have to be a POSIX path, aDegree have to be in {0, 90, 180, 270, 360} on rotatePDFandSaveAt(oldPath as string, newPath as string, aDegree as integer) –Error Check if aDegree is not in {0, 90, 180, 270, 360} then error "Wrong Degree" set aURL to current application’s |NSURL|’s fileURLWithPath:oldPath set aPDFdoc to current application’s PDFDocument’s alloc()’s initWithURL:aURL set pCount to aPDFdoc’s pageCount() –count pages –Make Blank PDF set newPDFdoc to current application’s PDFDocument’s alloc()’s init() –Rotate Each Page repeat with i from 0 to (pCount – 1) set aPage to (aPDFdoc’s pageAtIndex:i) –Set Degree set curDegree to aPage’s |rotation|() –Get Current Degree (aPage’s setRotation:(aDegree + curDegree)) –Set New Degree (newPDFdoc’s insertPage:aPage atIndex:i) end repeat set aRes to newPDFdoc’s writeToFile:newPath return aRes as boolean end rotatePDFandSaveAt |
More from my site
(Visited 14 times, 1 visits today)