【问题标题】:Multipage tiff to pdf with a script带有脚本的多页 tiff 到 pdf
【发布时间】:2021-07-17 00:16:32
【问题描述】:

我正在尝试制作多页 tiff 文件的 pdf。我们在较新版本的 macOS 上尝试了this solution,它成功了。其他人可以帮我微调吗?

转换后,我喜欢将两个单独的 pdf 重新加入一个文件,并且我想在将文件添加到某个文件夹时自动运行它。

【问题讨论】:

    标签: applescript


    【解决方案1】:

    在您的 Mac 上创建常用文件夹。将以下脚本附加到它。该脚本将一次将 1 个多页 TIFF 转换为 1 个多页 PDF:

    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
    
    on adding folder items to this_folder after receiving these_items
        set aRes to convertMultiPageTiffToPDF(item 1 of these_items) of me
    end adding folder items to
    
    
    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
    
    
    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-14
      • 2011-06-10
      • 1970-01-01
      • 2018-05-11
      • 1970-01-01
      相关资源
      最近更新 更多