打开文件夹中的所有pdf文件,并保存为调整大小的jpg在其他文件夹

Open all pdf files in folder and save as resized jpgs in other folder

本文关键字:文件夹 调整 jpg 保存 其他 pdf 文件      更新时间:2023-09-26

我有一个脚本,检查图像是否比250px宽,如果它比300px高,如果这些语句中的任何一个是真的,它应该调整它们的大小以适应这两个值。然后,它应该将它们保存为jpg,扩展名为large的文件夹中的文件名。然而,我不知道如何使photoshop打开所有文件在一个给定的文件夹和执行脚本,我也不知道如何正确地导出它们,photoshop停止时,它试图导出。

下面是我的代码:
// get a reference to the current (active) document and store it in a variable named "doc"
 doc = app.activeDocument;  
// change the color mode to RGB.  Important for resizing GIFs with indexed colors, to get better results
doc.changeMode(ChangeMode.RGB);  
// these are our values for the END RESULT width and height (in pixels) of our image
var fWidth = 250;
var fHeight = 300;
// do the resizing.  if height > width (portrait-mode) resize based on height.  otherwise, resize based on width
if (doc.height > 300) { doc.resizeImage(null,UnitValue(fHeight,"300"),null,ResampleMethod.BICUBIC); }
else if (doc.width > 250) {  doc.resizeImage(null,UnitValue(fWidth,"250"),null,ResampleMethod.BICUBIC); }

// Makes the default background white
var white = new SolidColor(); 
white.rgb.hexValue = "FFFFFF";
app.backgroundColor = white;
// Convert the canvas size as informed above for the END RESULT app.activeDocument.resizeCanvas(UnitValue(fWidth,"px"),UnitValue(fHeight,"px"));
// our web export options
var options = new ExportOptionsSaveForWeb();
options.quality = 70;
options.format = SaveDocumentType.JPEG;
options.optimized = true;
var newName = 'web-'+doc.name+'.jpg';
doc.exportDocument(File(doc.path+'/images/'+newName);

打开PDF文件有点困难。正如我在几周前的请求中所述:Photoshop JavaScript:打开PDF作为智能对象的选项

我的解决办法是使用一个动作(从动作面板)打开文件(模态控制,设置有效的PDF渲染),并启动脚本。

您可以使用该操作导出为web JPG。

如果您想使用脚本,File需要一个完整的路径。

var destFile = new File ("~/Desktop/" + "web-" + doc.name + ".jpg");

还需要exportDocument的参数(非可选)。

doc.exportDocument(destFile, ExportType.SAVEFORWEB, options);