如何在 MAC 上转换图像格式

use*_*318 -1 macos qt applescript

我在 MAC 上工作,我想在 Mac 机器上使用 Qt 或 APplescript 将 .bmp 和 .JPEG 文件转换为 .PDF 文件格式。我的操作系统版本是 10.6 。

谢谢

在此处输入图片说明

Dig*_*uma 6

事实证明,OSX 有命令行实用程序,对这种叫做sips的东西很有用。我在不同的答案中发布了这个,因为这与我的其他答案中的 UI 脚本完全不同。

您可以创建一个小的包装器 shell 脚本来执行您需要的操作:

#!/bin/bash

sips -s format pdf "$1" --out "${1%.*}.pdf"
Run Code Online (Sandbox Code Playgroud)

将其保存为例如 img2pdf,然后赋予它执行权限:

chmod +x img2pdf
Run Code Online (Sandbox Code Playgroud)

然后您可以使用以下命令进行转换:

./img2pdf.txt "/Users/mmouse/Desktop/Screen Shot 2013-07-22 at 9.00.36 AM.png"
Run Code Online (Sandbox Code Playgroud)

如果您真的不希望在 shell 脚本中使用它并且必须有一个 Applescript,那么您可以从 Applescript 调用相关命令:

set ImgFile to "/Users/mmouse/Desktop/Screen Shot 2013-07-22 at 9.00.36 AM.png"

do shell script "imgfile=" & quoted form of ImgFile & " ; sips -s format pdf \"$imgfile\" --out \"${imgfile%.*}.pdf\""
Run Code Online (Sandbox Code Playgroud)

作为一个兴趣点,如果您需要做相反的事情,即将 .pdf 转换为 .png,那么OSX 中的图像事件脚本扩展可以轻松完成此操作:

set ImgFile to "/Users/mmouse/Desktop/Screen Shot 2013-07-18 at 2.52.47 PM.pdf"
tell application "Image Events"
    set Img to open file ImgFile
    save Img as PNG
end tell
Run Code Online (Sandbox Code Playgroud)

但不幸的是,图像事件脚本扩展只允许读取而不是写入 PDF 文件,因此在您的特定情况下没有用。