加载中...
JSX 批量PDF转JPG 可自定义尺寸

发布时间:2021.09.03查看:161 评论:0

本帖最后由 fenrir 于 2021-9-3 13:32 编辑

源码如下:
//批处多个文件
var prefs = new Object()
var sourceFolder = Folder.selectDialog('Please select the imported folder:', Folder(prefs.sourceFolder))
var docs = sourceFolder.getFiles("*.pdf")
for (index in docs) {
    doc = docs[index]
    //判断输入文件格式是否为PDF
    if (doc.name.indexOf('pdf') == -1) {
        continue
    }
    open(File(doc))
    var doc = activeDocument
    doc.changeMode(ChangeMode.RGB) //图像模式RGB
    app.preferences.rulerUnits = Units.MM
    activeDocument.resizeImage(120) //保持长宽比,宽为120,高度随宽度变化,默认分辨率
    doc.rotateCanvas(90) //顺时针旋转90°
    var jpegOptions = new JPEGSaveOptions()
    //jpegOptions.embedColorProfile = true
    //jpegOptions.formatOptions = FormatOptions.STANDARDBASELINE
    //jpegOptions.matte = MatteType.NONE
    jpegOptions.quality = 12 //保存质量1~12
    saveFile = new File(sourceFolder + '/' + doc.name.split('.')[0] + '副本.jpg')//文件名称
    activeDocument.saveAs(saveFile, jpegOptions, true) //保存确认
    activeDocument.close(SaveOptions.DONOTSAVECHANGES)//保存后自动关闭
}



//处理单个文件
var prefs = new Object()
var file_name = open(File(openDialog()))
var doc = activeDocument
doc.changeMode(ChangeMode.RGB)//图像模式RGB
app.preferences.rulerUnits = Units.MM
activeDocument.resizeImage(120)
doc.rotateCanvas(90) //顺时针旋转90°
var jpegOptions = new JPEGSaveOptions()
jpegOptions.quality = 12 //保存质量1~12
saveFile = new File("~/desktop/" + doc.name.split('.')[0] + '副本.jpg')//存储至桌面
activeDocument.saveAs(saveFile, jpegOptions, true) //保存确认
activeDocument.close(SaveOptions.DONOTSAVECHANGES)//保存后自动关闭






分享

收藏(1)

点赞

评论列表

  • 暂无评论数据

快速回复