script to save as pdf

Explorer ,
Apr 30, 2020 Apr 30, 2020

Copy link to clipboard

Copied

I need script to save illustrator file to lores in same directory of AI file with same file naming.

Please help me on this.

Thanks

TOPICS
Scripting

Views

2.9K

Likes

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

correct answers 1 Correct Answer

Adobe Community Professional , Apr 30, 2020 Apr 30, 2020
Hi,Try this 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() This will allow you save Illustartor document in PDF fo...

Likes

Translate

Translate
Adobe Community Professional ,
Apr 30, 2020 Apr 30, 2020

Copy link to clipboard

Copied

function saveAsPDf()
{
	var doc = app.activeDocument;
	var saveName = doc.fullName.replace(/\.ai$/,".pdf");

	var pdfSaveOpts = new PDFSaveOptions();

	//change this to whatever preset you want;
	pdfSaveOpts.preset = "[Smallest File Size]";

	
	doc.saveAs(File(saveName,pdfSaveOpts));
}
saveAsPDf();

Likes

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
Explorer ,
Apr 30, 2020 Apr 30, 2020

Copy link to clipboard

Copied

Hi there,

You should be able to use this:

 

// The active document  
var doc = app.activeDocument;  
// The path of the original document  
var originalDocPath = doc.path;  
// The name of the original document  
var originalDocName = doc.name;  
// An array of all the layers in the active document  
var allLayers = doc.layers;  
// Get just the file name. Ignore the file extension .pdf and .ai  
originalDocName = originalDocName.replace(/\.pdf|\.ai/gi, "")  
  
  
{
// Setup pdf save options  
var opts = new PDFSaveOptions();  
// Use the preset named "XXX"  
opts.pDFPreset = "your PDF preset name here";  
// Save the document in the original folder using the original name with _LR suffix  
doc.saveAs(File(originalDocPath + "/" + originalDocName + "_LR.pdf"), opts);  

app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

}

 

Obviously you'll need a Low Res PDF preset as just naming the file with _LR.pdf won't achieve that. And you can comment out the 'app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);' if you don't want your file to close after saving the PDF. That's just the way we do things with this script.

Likes

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
Explorer ,
May 13, 2020 May 13, 2020

Copy link to clipboard

Copied

Hello,

Is it possible to have the same script but with all the documents open and not just the active document?

Likes

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 Community Professional ,
May 13, 2020 May 13, 2020

Copy link to clipboard

Copied

Yes, it is possible. You have to loop over all the documents. Here is the sample script that will loop all the documents and save as PDF

 

function saveAsPDF() {
    var allDocumentsLength = app.documents.length;
    for (var i = allDocumentsLength - 1; i >= 0; i--) {
        app.activeDocument = app.documents[i]; // Not necessary, only required whn you want to make document as active.
        var doc = app.documents[i];
        var pdfFile = new File(doc.path + "/" + doc.name.split('.')[0] + '.pdf');
        var pdfOptions = new PDFSaveOptions();
        pdfOptions.compatibility = PDFCompatibility.ACROBAT5;
        pdfOptions.generateThumbnails = true;
        pdfOptions.preserveEditability = false;
        pdfOptions.preset = "[Smallest File Size]";
        doc.saveAs(pdfFile, pdfOptions);
        doc.close(SaveOptions.DONOTSAVECHANGES);
    }
}

saveAsPDF();

 

Thanks

Best regards

Likes

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
Explorer ,
May 13, 2020 May 13, 2020

Copy link to clipboard

Copied

Thank you, by cons I do not see or I indicate the export setting that I want.

Likes

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 Community Professional ,
May 29, 2020 May 29, 2020

Copy link to clipboard

Copied

Hi,

What export setting you would like to use, please specify.

Best regards

Likes

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
Explorer ,
Jun 02, 2020 Jun 02, 2020

Copy link to clipboard

Copied

Bonjour,

On m'a aidé a trouver une réponse sur un autre post.
Il y a une erreur dans le code il faut remplacer :

        pdfOptions.preset = "[Smallest File Size]";

par 

pdfOptions.pDFPreset = "[Smallest File Size]";

 

Et après on peux choisir le parametre d'export PDF qu'on souhaite.

Likes

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
New Here ,
Apr 17, 2021 Apr 17, 2021

Copy link to clipboard

Copied

Im having alot of issues with saving as PDF.

I can save it as a regular AI file, but anytime i add PDFSaveOptions(), I get the error:

 

Enumerated value expected

 

or

 

Runtime Error: Error Code# 1226: Enumerated value expected @ file '~/Documents/Adobe%20Scripts/index.jsx' [line:64, col:NaN]
 
 
Any idea why thismight be?

Likes

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
New Here ,
Apr 17, 2021 Apr 17, 2021

Copy link to clipboard

Copied

Seems like a simple close/reopen fixed this problem

Likes

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 Community Professional ,
Apr 30, 2020 Apr 30, 2020

Copy link to clipboard

Copied

Hi,

Try this

 

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()

 

 

This will allow you save Illustartor document in PDF format. 

 

Let us know if this helps you.

Thanks

Best regards

Likes

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
Explorer ,
Apr 30, 2020 Apr 30, 2020

Copy link to clipboard

Copied

please add close funtion at the end. dont need to save ai file it is already saved. once pdf is created file should be closed

Likes

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 Community Professional ,
Apr 30, 2020 Apr 30, 2020

Copy link to clipboard

Copied

Hi @abhijeett89122812,

simple add:

app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

 

Likes

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
Participant ,
Apr 24, 2021 Apr 24, 2021

Copy link to clipboard

Copied

Hello,

there is way  to select  folder location before saving?

The rest script works fine!

Likes

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 Community Professional ,
May 03, 2021 May 03, 2021

Copy link to clipboard

Copied

Hi,

Yes, you can ask the user to select the location from the following line of code

var _location = Folder.selectDialog("Select location");
alert(_location);

 

Best regards

Likes

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
Participant ,
May 15, 2021 May 15, 2021

Copy link to clipboard

Copied

It works great, thank you!

May be you can help me how i can set a default save location?

Likes

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
Participant ,
May 15, 2021 May 15, 2021

Copy link to clipboard

Copied

LATEST

I forgot to mention that I am on win 10 and my save location is a network folder

\\STICKITSERVER2\stickitsyn\orders\

Likes

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