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

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

Explorer ,
Mar 04, 2022 Mar 04, 2022
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;
}
TOPICS
Import and export , Scripting
1.9K
Translate
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

correct answers 1 Correct answer

Guide , Mar 04, 2022 Mar 04, 2022
Adobe
Guide ,
Mar 04, 2022 Mar 04, 2022
Translate
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
Explorer ,
Mar 04, 2022 Mar 04, 2022
LATEST
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);
Translate
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