function main() {
var files, sourceDoc, targetFile;
var fileType = "*.pdf"; // 文件類型
var sourceFolder = Folder.selectDialog('選中你要進行壓縮PDF的文件夾', '~');
if (sourceFolder != null) {
files = new Array();
files = sourceFolder.getFiles(fileType); // 獲取所有文件夾里面匹配的類型文件
if (files.length > 0) {
for (i = 0; i < files.length; i++) {
sourceDoc = app.open(files[i]);
targetFile = getNewName();
sourceDoc.saveAs(targetFile, getPDFOptions());
sourceDoc.close();
}
alert("共"+ files.length + '個文件壓縮成功~');
}
else {
alert('沒找到相關匹配文件.');
}
} else {
alert("取消執(zhí)行,沒有選擇目標文件夾.")
}
function getNewName() {
var ext, docName, newName, saveInFile, docName;
docName = sourceDoc.name;
ext = '_low.pdf';
newName = "";
for (var i = 0; docName[i] != "."; i++) {
newName += docName[i];
}
newName += ext;
saveInFile = new File(sourceFolder + '/' + newName);
return saveInFile;
}
function getPDFOptions() {
// Create the PDFSaveOptions object to set the PDF options
var saveOpts;
saveOpts = new PDFSaveOptions();
// 兼容性
saveOpts.compatibility = PDFCompatibility.ACROBAT6;
// 關閉生成縮略圖
saveOpts.generateThumbnails = false;
// 不保留編輯功能
saveOpts.preserveEditability = false;
// 壓縮 -> 灰度位圖圖像 自動JPEG low
saveOpts.grayscaleCompression = CompressionQuality.AUTOMATICJPEGLOW
saveOpts.colorCompression = CompressionQuality.AUTOMATICJPEGLOW
saveOpts.colorDownsampling = 100
saveOpts.colorDownsamplingImageThreshold = 150
// saveOpts.colorConversionID = ColorDestination.COLORDESTINATIONPROFILE
return saveOpts;
}
}
main()
承擔因您的行為而導致的法律責任,
本站有權保留或刪除有爭議評論。
參與本評論即表明您已經閱讀并接受
上述條款。