Skip to main content
This topic has been closed for replies.
Correct answer SuperMerlin

#target photoshop;

var saveFile = File(Folder.desktop + "/test.pdf");

SavePDF(saveFile);

function SavePDF(saveFile){

pdfSaveOptions = new PDFSaveOptions();

activeDocument.saveAs(File(saveFile), pdfSaveOptions, true, Extension.LOWERCASE);

};

1 reply

SuperMerlin
SuperMerlinCorrect answer
Inspiring
April 9, 2019

#target photoshop;

var saveFile = File(Folder.desktop + "/test.pdf");

SavePDF(saveFile);

function SavePDF(saveFile){

pdfSaveOptions = new PDFSaveOptions();

activeDocument.saveAs(File(saveFile), pdfSaveOptions, true, Extension.LOWERCASE);

};

AG_Ps_100
AG_Ps_100Author
Inspiring
April 10, 2019

Thank you!

I've added try and catch to the code and also take active document's name:

#target photoshop;

  

try

{

    var savePath = activeDocument.path;

    var saveFile = File(savePath + "/" + app.activeDocument.name + ".pdf");

    SavePDF(saveFile);        

}

catch(e)

{

    savePath = Folder.selectDialog("select folder");

    var saveFile = File(savePath + "/" + app.activeDocument.name + ".pdf");

    SavePDF(saveFile);        

}

          

function SavePDF(saveFile){

pdfSaveOptions = new PDFSaveOptions();

activeDocument.saveAs(File(saveFile), pdfSaveOptions, true, Extension.LOWERCASE);

};

by the way, I haven't tried try and catch too many times, I wanted to know if there's a better way to do it where I only need to write once these two lines:

var saveFile = File(savePath + "/" + app.activeDocument.name + ".pdf");

SavePDF(saveFile);

SuperMerlin
Inspiring
April 10, 2019

#target photoshop;

try { 

    savePath = activeDocument.path; 

}catch(e){  

    savePath = Folder.selectDialog("select folder"); 

}

var Name = app.activeDocument.name.replace(/\.[^\.]+$/, '');

var saveFile = File(savePath + "/" + Name + ".pdf");  

SavePDF(saveFile);          

 

function SavePDF(saveFile){  

pdfSaveOptions = new PDFSaveOptions();  

activeDocument.saveAs(File(saveFile), pdfSaveOptions, true, Extension.LOWERCASE);  

};