拆分多页tiff的applescript [英] applescript to split multipage tiff

查看:21
本文介绍了拆分多页tiff的applescript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作多页 tiff 文件的 pdf.我设法在带有图像魔法的窗口中做到了这一点.在一个项目中,我们正在与带有 OSX 的 macbook 一起工作(对我来说是新的).应该有可能.

I'm trying to make a pdf of a multipage tiff file. I managed to do that in windows with image magick. In a project we are working together with a macbook with OSX (new to me). And there should it be possible to.

是否有脚本/自动机...来执行此操作.现在我在预览中手动拆分多页 tiff(2 页):打开 tiff,将每一页拖到一个文件夹中,然后运行脚本来制作 pdf.

Is there a script/automator... to do this. Now I split the multipage tiff (2pages) in preview manually: open the tiff, drag each page to a folder and than I run a script to make a pdf.

可以在脚本中完成吗?

推荐答案

我向所有试图在可能的情况下不使用第三方应用程序的用户致以问候.OP 提出的问题比本节中出现的许多琐碎问题有趣得多.此外,我不明白两个用户对所提出问题的负面影响.解决方法如下:

I greet every user who tries to do without third-party applications where possible. The question asked by the OP is much more interesting than many of the trivial questions popping up in this section. Moreover, I do not understand the minuses put down by two users to the question asked. Here's the solution:

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

-- select TIFF
set anAlias to choose file of type {"public.tiff"} with prompt "Select Multi-page tiff file"

-- get selected TIFF's  name and base name
tell application "Finder"
    set pathString to NSString's stringWithString:(name of anAlias)
    set baseName to (pathString's stringByDeletingPathExtension()) as text
end tell

-- make new destination folder (if it doesn't exist already)
tell application "Finder"
    try
        set destinationFolder to (make new folder at desktop with properties {name:baseName}) as text
    on error
        set destinationFolder to "" & (path to desktop folder) & baseName
    end try
end tell
set destinationFolder to POSIX path of destinationFolder

--Read Multi-Page TIFF
set aURL to |NSURL|'s fileURLWithPath:(POSIX path of anAlias)
set aImage to NSImage's alloc()'s initWithContentsOfURL:aURL
set aRawimg to aImage's TIFFRepresentation()
set eachTiffPages to (NSBitmapImageRep's imageRepsWithData:aRawimg) as list

-- extract each tiff page as PDF file
set pageNum to 1
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)
    --Make Blank PDF
    set aPDFdoc to PDFDocument's alloc()'s init()
    -- set PDF first page's content to next image
    (aPDFdoc's insertPage:(PDFPage's alloc()'s initWithImage:aImg) atIndex:0)
    -- write PDF to destination
    set outPutPath to destinationFolder & "/Page_" & pageNum & ".pdf"
    (aPDFdoc's writeToFile:outPutPath)
    set pageNum to pageNum + 1
end repeat

这篇关于拆分多页tiff的applescript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆