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

script to save as pdf

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

8.3K

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

Community Expert , 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

...

Votes

Translate

Translate
Adobe
Community Expert ,
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();

Votes

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.

Votes

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?

Votes

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
Community Expert ,
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

Votes

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.

Votes

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

Copy link to clipboard

Copied

Hi,

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

Best regards

Votes

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.

Votes

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?

Votes

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

Votes

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
Community Beginner ,
Nov 01, 2021 Nov 01, 2021

Copy link to clipboard

Copied

Hi! This script has helped me a lot, it is fantastic!

Do you know if there is any line of code to replace an existing file with the same name (including the _LR) when using the script?

Thank you so much

Votes

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 ,
Mar 12, 2022 Mar 12, 2022

Copy link to clipboard

Copied

Would it be possible to save a HiRes and a LoRes version?

What changes would i have to make?

 

Thanks in advance!

 

Andreas

Votes

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 ,
Aug 24, 2023 Aug 24, 2023

Copy link to clipboard

Copied

LATEST

Yep.  That would be very helpful.  I have one for InDesign that exports PDFx1a>Medium>Low res pdfs all in one shot.  

~Roy

Votes

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 ,
Mar 12, 2022 Mar 12, 2022

Copy link to clipboard

Copied

The script works perfect!

Is it possible to alter the script to save a lowres and a hires version ?

Votes

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
Community Expert ,
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

Votes

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

Votes

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

Copy link to clipboard

Copied

Hi @abhijeett89122812,

simple add:

app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

 

Votes

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
Engaged ,
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!

Votes

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
Community Expert ,
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

Votes

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
Engaged ,
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?

Votes

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

Copy link to clipboard

Copied

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

\\STICKITSERVER2\stickitsyn\orders\

Votes

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