• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Save as pdf without dialog , default save location

Engaged ,
May 15, 2021 May 15, 2021

Copy link to clipboard

Copied

Hello,

i want to add to following script a default save folder location.

Any idea how?

( the default location i want to use is a network folder, \\SERVER2\customer requests\orders)
"function saveAsPDF() {
var pdfFile = new File(app.activeDocument.path + "/" + app.activeDocument.name.split('.')[0] + '.pdf');
var pdfOptions = new PDFSaveOptions();
pdfOptions.compatibility = PDFCompatibility.ACROBAT5;
pdfOptions.generateThumbnails = true;
pdfOptions.preserveEditability = false;
pdfOptions.preset = "[Smallest File Size]";
app.activeDocument.saveAs(pdfFile, pdfOptions);
}
saveAsPDF()"

TOPICS
Scripting

Views

704

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Explorer ,
May 15, 2021 May 15, 2021

Copy link to clipboard

Copied

Hi simosp,
here are some snippets I took from a much more complicated project of mine, hope you could use some of that.

These snippets will not work alone!!!

Keep in Mind that you need a swtich for Windows of MacOS

 if($.os.match("Windows")) {
    //Paths Windows Netzwerk
    var path1 = "//Windows/path1/deeper"; //Windows
    }
    else {
      //Paths MacOS Netzwerk
      var path1 = "MacOS/path1/deeper"; //MacOS
    }

---

//saveAS PDF
function exportFileToPdf(fileNameOnlyID, pathPdf, pdfPresetName) {
  if (Folder(pathPdf).exists) {
    var compPath = pathPdf + "/" + fileNameOnlyID + ".pdf";
    var pdfPathPlusName = new File(compPath);
    if (!pdfPathPlusName.exists) {
      doc.saveAs(pdfPathPlusName, pdfPresetName);
    } else {
      var res = confirm("Die PDF-Datei existiert bereits hier:\r" + compPath + "\rSoll sie überschrieben werden?", true, "Problem");
      // if the user hits no, move on without saving this
      if (res !== true) {
        return; //get out of this function
      } else {
        doc.saveAs(pdfPathPlusName, pdfPresetName);
        }
      }
  } else {
    alert("Ein oder mehrere Ordner existieren nicht. \rFunktion: pdf");
  }
}

exportFileToPdf(fileNameOnlyID, path1, PDFX1);

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 15, 2021 May 15, 2021

Copy link to clipboard

Copied

//to set a default folder path
var mySaveFolderPath = "/SERVER2/customer requests/orders/";

//to get a save dialog that defaults to the above folder:
//if you don't want the dialog at all and you always want to save
//directly into the orders folder, just comment this line out.
mySaveFolderPath = Folder.selectDialog("Choose save folder", mySaveFolderPath);


//set the new file name to the save folder path + name of document
//and setup pdf save options
var saveFile = File(mySaveFolderPath + app.activeDocument.name.replace(/^\.(ai)|(svg)|(eps)/i,".pdf");
var pdfSaveOpts = new PDFSaveOptions();
pdfSaveOpts.compatibility = PDFCompatibility.ACROBAT5;
pdfSaveOpts.generateThumbnails = true;
pdfSaveOpts.preserveEditability = false;
pdfSaveOpts.preset = "[Smallest File Size]";

//save the file
app.activeDocument.saveAs(saveFile,pdfSaveOpts)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
May 18, 2021 May 18, 2021

Copy link to clipboard

Copied

Hello!

Althought script call correctly the select folder dialog, it is not easy to select folder

The save as native illustrator folder is much easier.

There is a way to call illustrators save as dialog from the script?

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
May 18, 2021 May 18, 2021

Copy link to clipboard

Copied

I think to get the Ai native saver you have to use a dynamic action, and also make sure it is set to show the dialog.

 

Otherwise, there's one small edit to @Disposition_Dev 's code which will still use the pathetic tiny Windows file-saver but will take you there:


var mySaveFolderPath = "/SERVER2/customer requests/orders/";
var possibleFile = File(mySaveFolderPath + "/test.pdf");
var saveLocation = possibleFile.saveDlg("Save the file");
// should take you right to that folder with the name "test.pdf" already pre-filled.
if (!saveLocation) {
  alert("User cancelled saving op.");
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
May 24, 2021 May 24, 2021

Copy link to clipboard

Copied

LATEST

Hello,

script is fine now, thank you!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines