所以我试着将一堆PDF文件批量转换成JPEG文件,作为更大的Applescript的一部分,我发现"PDF打开选项“中的一些参数被忽略了。即“高”、“宽”和“约束比例”参数。
这段代码直接取自Photoshop CS3脚本指南(当然,文件名已更改):
tell application "Adobe Photoshop CS3"
set myFilePath to alias "WABEL0457937:Users:Charles:Desktop:8925.pdf"
with timeout of 10000 seconds
open myFilePath as PDF with options {class:PDF open options, height:pixels 100, width:pixels 200, mode:RGB, resolution:72, use antialias:true, page:1, constrain proportions:false}
end timeout
end tell
在生成的文件中,“分辨率”是正确的,但是高度和宽度是使用PDF的原始高度和宽度乘以分辨率来计算的,并且图像被约束为原始比例。
我认为这可能会与指定分辨率和以像素为单位的高度/宽度相冲突,所以我尝试省略分辨率,但后来它就默认为300。
还有谁创建了一个打开PDF的脚本,然后运行到这个脚本中?
发布于 2009-09-29 11:08:42
在查看Photoshop CS3的AS字典时,它指出,自CS2以来,PDF打开选项的高度、宽度和约束比例属性都已被弃用。(但让Adobe自行清理,从而进一步增加其接口的不一致性。)
发布于 2009-09-30 09:02:54
我的方法是使用shell脚本确定72DPI的PDF分辨率,然后计算栅格化的最佳分辨率以达到所需的尺寸。
(仅供参考:"str_replace“是一个自定义函数,用于查找和替换字符串中的文本--它不是内置的Applescript函数。)
set pageHeight to do shell script "/usr/bin/mdls -name kMDItemPageHeight " & quoted form of (POSIX path of this_item as string)
set pageHeight to my str_replace("kMDItemPageHeight = ", "", pageHeight)
set pageWidth to do shell script "/usr/bin/mdls -name kMDItemPageWidth " & quoted form of (POSIX path of this_item as string)
set pageWidth to my str_replace("kMDItemPageWidth = ", "", pageWidth)
if (pageHeight as number) is greater than (pageWidth as number) then
set pdf_resolution to round (1000 / (pageHeight as number) * 72) rounding up
else
set pdf_resolution to round (1000 / (pageWidth as number) * 72) rounding up
end if
open this_item as PDF with options {class:PDF open options, resolution:pdf_resolution, mode:RGB, use antialias:true, suppress warnings:false, use page number:true, page:1, crop page:media box}
我使用“四舍五入”来确保结果等于或略高于我的目标分辨率。这只是个大概的精确度,但比我一开始的要好。
https://stackoverflow.com/questions/1480086
复制相似问题