Skip to main content
sebastianf15538645
Inspiring
April 27, 2018
Answered

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

  • April 27, 2018
  • 2 replies
  • 4523 views

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!

This topic has been closed for replies.
Correct answer q3player

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.

2 replies

sebastianf15538645
Inspiring
April 27, 2018

Works like a charm - thank you very much!!

pixxxelschubser
Community Expert
Community Expert
April 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

q3playerCorrect answer
Inspiring
April 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.

Inspiring
November 2, 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!

Known Participant
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