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

How can I modify the "Save as PDF" script to avoid the save dialogue?

Explorer ,
Apr 27, 2018 Apr 27, 2018

Okay, I found out how to modify the "Save as PDF" javascript supplied with Illustrator so that it renders the .pdf with my preferred .joboption (e.g. X3) - what I'm lacking and don't seem to be able to find out via google is how to suppres the save dialogue (asking me about the location where to save the file every time I invoke that script).

I'd like the script to save the PDF

- in exactly the same location as the .ai document

- overwrite any probably existing .pdf file with the same name without asking

Can anybody here help me how to do this trick?

Thx in advance!

TOPICS
Scripting
4.5K
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

Engaged , Apr 27, 2018 Apr 27, 2018

var doc = app.activeDocument;

var pdfOption = 'PDFX3_CanDo_X3'; // Name of your PDF setting

var pdfSuff = '.pdf'; // Suffix for PDF

function getOptions (set) {

    var options = new PDFSaveOptions ();

    options.pDFPreset = set;

    return options;

    }

function saveCopyAsPDF (set, suff) {

        var original_file = doc.fullName;

        var arr = doc.name.split(".");

        var extension = "";

        if (arr.length > 1) {

            extension = "." + arr.pop()

            };

        var filename = arr.j

...
Translate
Adobe
Engaged ,
Apr 27, 2018 Apr 27, 2018

var doc = app.activeDocument;

var pdfOption = 'PDFX3_CanDo_X3'; // Name of your PDF setting

var pdfSuff = '.pdf'; // Suffix for PDF

function getOptions (set) {

    var options = new PDFSaveOptions ();

    options.pDFPreset = set;

    return options;

    }

function saveCopyAsPDF (set, suff) {

        var original_file = doc.fullName;

        var arr = doc.name.split(".");

        var extension = "";

        if (arr.length > 1) {

            extension = "." + arr.pop()

            };

        var filename = arr.join(".");

        var destFolder = null;

            destFolder = activeDocument.path

        var options = this.getOptions (set);

        var targetFile;   

            targetFile = this.getTargetFile (filename, suff, destFolder);

            doc.saveAs (targetFile, options);

        doc.close ();

        app.open (File (original_file));

        }

function getTargetFile (docName, ext, destFolder) {

    var newName = "";

        newName = docName + ext;

    var myFile = new File (destFolder + '/' + newName);

    return myFile;

}

saveCopyAsPDF (pdfOption, pdfSuff);

You will have to modify at least the second line and insert the name of your own pdf export settings. The script saves a PDF of your active document in the same folder as the original AI. After that it closes the PDF and re-opens the original AI file.

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
Participant ,
Nov 02, 2018 Nov 02, 2018

This is brilliant. I have been searching for years for a script that would use a PDF preset to save out a PDF. Thank you!

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 ,
May 15, 2019 May 15, 2019

This is the closest workaround to EXPORTING the current file to PDF, however since it SAVES to PDF and then re-opens your original AI file, you lose any ability to UNDO previous actions.

If you wish Adobe would give us a proper Export PDF menu, (as it already exists in inDesign), please vote up this feature request here:

PDF Export – Adobe Illustrator Feedback

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
Community Beginner ,
Nov 18, 2019 Nov 18, 2019
LATEST

Is it possible to set this up to batch a folder of AI files? I was trying to do something similar with the Save As PDF Sample script but could not get it to work with my PDF preset.

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 ,
Apr 27, 2018 Apr 27, 2018

Works like a charm - thank you very much!!

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
Community Expert ,
Apr 27, 2018 Apr 27, 2018

Only for addition

To change the original Save as PDF.jsx:

Change line #52 to

destFolder = sourceFolder;

To suppres the prompt (which ask for the file type) - comment out line #44 and

change line #47 to

files = sourceFolder.getFiles ("*.ai");

Have fun

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