AppleScript名:multi page tiffを読み込んで、PDFにする v2 |
— Created 2015-01-01 by Takaaki Naganoya — Modified 2016-04-18 by Takaaki Naganoya — 2016 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "QuartzCore" use framework "Quartz" use framework "AppKit" property |NSURL| : a reference to current application’s |NSURL| property NSString : a reference to current application’s NSString property PDFPage : a reference to current application’s PDFPage property NSImage : a reference to current application’s NSImage property PDFDocument : a reference to current application’s PDFDocument property NSBitmapImageRep : a reference to current application’s NSBitmapImageRep set a to choose file of type {"public.tiff"} with prompt "Select Multi-page tiff file" –tiff set aRes to convertMultiPageTiffToPDF(a) of me on convertMultiPageTiffToPDF(anAlias) –Make Output Path set b to POSIX path of anAlias set bb to changeExtensionInPath("pdf", b) –OutPath –Read Multi-Page TIFF set aURL to |NSURL|’s fileURLWithPath:b set aImage to NSImage’s alloc()’s initWithContentsOfURL:aURL set aRawimg to aImage’s TIFFRepresentation() set eachTiffPages to (NSBitmapImageRep’s imageRepsWithData:aRawimg) as list –Make Blank PDF set aPDFdoc to PDFDocument’s alloc()’s init() set pageNum to 0 repeat with curPage in eachTiffPages set thisImage to contents of curPage set aImg to (NSImage’s alloc()’s initWithSize:(thisImage’s |size|())) (aImg’s addRepresentation:thisImage) (aPDFdoc’s insertPage:(PDFPage’s alloc()’s initWithImage:aImg) atIndex:pageNum) set pageNum to pageNum + 1 end repeat return (aPDFdoc’s writeToFile:bb) as boolean end convertMultiPageTiffToPDF –ファイルパス(POSIX path)に対して、拡張子のみ付け替える on changeExtensionInPath(extStr as string, aPath as string) set pathString to NSString’s stringWithString:aPath set theExtension to pathString’s pathExtension() set thePathNoExt to pathString’s stringByDeletingPathExtension() set newPath to thePathNoExt’s stringByAppendingPathExtension:extStr return newPath as string end changeExtensionInPath |
More from my site
(Visited 32 times, 1 visits today)