指定PDFのサイズ(幅、高さ)をPointで取得するAppleScriptです。
以前に掲載したバージョンでは、macOS 10.13以降でboundsの値の返り方が変わったことに対応できていないので(それ以前に作ったので無理もないというか、勝手にAppleが仕様を変えたのが悪い)、対処してみました。
AppleScript名:PDFのサイズをpointで取得 v2.scptd |
— – Created by: Takaaki Naganoya – Created on: 2019/09/28 — – Copyright © 2019 Piyomaru Software, All Rights Reserved — use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "Quartz" use framework "AppKit" property |NSURL| : a reference to current application’s |NSURL| property PDFDocument : a reference to current application’s PDFDocument set aHFSPath to (choose file of type {"com.adobe.pdf"} with prompt "Select PDF") set sizeRes to retPDFSizeInfo(aHFSPath) of me –> {width:595.28, height:841.89} –PDFのサイズを取得する(単位:Point) on retPDFSizeInfo(aHFSPath) set aPOSIX to POSIX path of aHFSPath set aURL to (|NSURL|’s fileURLWithPath:aPOSIX) set aPDFdoc to PDFDocument’s alloc()’s initWithURL:aURL set pCount to aPDFdoc’s pageCount() set aPage to aPDFdoc’s pageAtIndex:0 set aBounds to aPage’s boundsForBox:(current application’s kPDFDisplayBoxMediaBox) set aClass to class of aBounds if aClass = record then set aSize to |size| of aBounds else if aClass = list then set aWidth to item 1 of item 2 of aBounds set aHeight to item 2 of item 2 of aBounds set aSize to {width:aWidth, height:aHeight} else error "Wrong PDF….Can not get bounds from PDF" end if return aSize end retPDFSizeInfo |
More from my site
(Visited 106 times, 1 visits today)