Skip to main content
Inspiring
March 4, 2022
Answered

AI Scripting - Save as PDF using a preexisting Adobe PDF Preset

  • March 4, 2022
  • 1 reply
  • 2046 views
I wrote an Illustrator script that draws shapes. The last step of the process is to save the a PDF of the doc to the desktop.
 
I managed to write a code that works correctly, but I cannot figure out how to get it to use a preexisting PDF Preset; it just uses the app default. Does anyone know how I can fix this? Also, this code seems a bit messy; is there a more straightforward way to write the code?
 
Thanks for your help!
 
//NAME OF PDF PRESET TO USE
var presetName = "My Preset";
var newFileName = "0000.pdf";

 

//NEW FILE PATH
var newFile = new File("~/Desktop/" + newFileName);

 

// USE FUNCTION TO SET PDF EXPORT OPTIONS
var saveOptions = this.getOptions();
 
app.activeDocument.saveAs(newFile, saveOptions);
 
function getOptions(){
// USE CUSTOM PDF EXPORT OPTIONS
var pdfSaveOpts = new PDFSaveOptions();
 
// CODE FOR PDF EXPORT OPTIONS
pdfSaveOpts.compatibility = PDFCompatibility.ACROBAT4;
pdfSaveOpts.viewAfterSaving = false;

 

return pdfSaveOpts;
}
This topic has been closed for replies.

1 reply

Inspiring
March 4, 2022
Awesome, thank you! Here is my finished code:
 
var fileName = "fileName";

//NAME OF NEW FILE
var newFileName = fileName + ".pdf";

//LOCATION OF NEW FILE
var newFile = new File("~/Desktop/" + newFileName);

//SET THE PDF SAVE OPTIONS
var pdfSaveOpts = new PDFSaveOptions();
      pdfSaveOpts.pDFPreset = "My PDF Preset";
      pdfSaveOpts.compatibility = PDFCompatibility.ACROBAT4;
      pdfSaveOpts.viewAfterSaving = false;
 
//SAVE DOC
app.activeDocument.saveAs(newFile, pdfSaveOpts);