Highlighted

script to save as pdf

Explorer ,
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

Adobe Community Professional
Correct answer by Charu Rajput | Adobe Community Professional

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

Topics

Scripting

Views

1.8K

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

script to save as pdf

Explorer ,
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

Adobe Community Professional
Correct answer by Charu Rajput | Adobe Community Professional

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

Topics

Scripting

Views

1.8K

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
Adobe Community Professional ,
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
Reply
Loading...
Community Beginner ,
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
Reply
Loading...
Explorer ,
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
Reply
Loading...
Adobe Community Professional ,
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
Reply
Loading...
Explorer ,
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
Reply
Loading...
Adobe Community Professional ,
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
Reply
Loading...
Kyvarit LATEST
Explorer ,
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
Reply
Loading...
Adobe Community Professional ,
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
Reply
Loading...
Explorer ,
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
Reply
Loading...
Most Valuable Participant ,
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
Reply
Loading...