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

Script to Set Default PDF Presets

Community Beginner ,
Jun 12, 2017 Jun 12, 2017

Copy link to clipboard

Copied

Hi guys -

I've been looking around for awhile for something that would help increase our workflow's efficiency. We have a certain setting we save all of our PDFs in [Color Press], but I can't figure out to set that as the default preset. Every time we Save As PDF, we have to change the PDF setting to [Color Press] manually. 

Is there a way to do so in AI or a script that will Save an open file to a preset instead of the [Illustrator Default]? We would ideally still need the option to choose where to save the PDF, as not all of our PDFs get saved into the same folder as the AI file.

Thanks in advance!

TOPICS
Scripting

Views

4.1K

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

Participant , Jun 13, 2017 Jun 13, 2017

This should help :

var main = function() {

var doc;

if ( !app.documents.length ) {

return;

}

doc = app.activeDocument;

var psts = app.PDFPresetsList;

var n = psts.length;

var found = false;

var presetName = "LUDILABEL",

f;

while ( n-- ) {

if ( psts==presetName) {

found = true;

break

}

}

if ( !found ) {

alert("Unable to find pdf preset "+presetName );

return;

}

var opts = new PDFSaveOptions();

opts.pDFPreset = presetName;

f= File.saveDialog ("Where di you want to save the file ?");

if ( !f ) return;

doc.saveAs ( f, opts

...

Votes

Translate

Translate
Adobe
Participant ,
Jun 13, 2017 Jun 13, 2017

Copy link to clipboard

Copied

This should help :

var main = function() {

var doc;

if ( !app.documents.length ) {

return;

}

doc = app.activeDocument;

var psts = app.PDFPresetsList;

var n = psts.length;

var found = false;

var presetName = "LUDILABEL",

f;

while ( n-- ) {

if ( psts==presetName) {

found = true;

break

}

}

if ( !found ) {

alert("Unable to find pdf preset "+presetName );

return;

}

var opts = new PDFSaveOptions();

opts.pDFPreset = presetName;

f= File.saveDialog ("Where di you want to save the file ?");

if ( !f ) return;

doc.saveAs ( f, opts );

}

main()

Loic

Ozalto | Productivity Oriented - Loïc Aigon

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 ,
Jun 13, 2017 Jun 13, 2017

Copy link to clipboard

Copied

Thank you so much Loic! This seems to be what we were looking for. 2 quick questions for you -

1) Is there a way to keep the filename when saving without having to retype it? When I run this script I have to rename the file (it's blank)

2) Can the default location to save open up where the AI file is located? Right now it opens up to save in the most recently saved location.

Thank you again, and sorry for the flurry of questions!

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 ,
Jun 13, 2017 Jun 13, 2017

Copy link to clipboard

Copied

var main = function() { 

var doc; 

if ( !app.documents.length ) { 

return; 

doc = app.activeDocument; 

var psts = app.PDFPresetsList; 

var n = psts.length; 

var found = false; 

var presetName = "SOME_PRESET_NAME",  

f; 

while ( n-- ) { 

if ( psts==presetName) { 

found = true; 

break ;

if ( !found ) { 

alert("Unable to find pdf preset "+presetName ); 

return; 

 

var opts = new PDFSaveOptions(); 

opts.pDFPreset = presetName; 

f = File ( doc.name );

f= f.saveDlg ("Where do you want to save the file ?"); 

if ( !f ) return; 

doc.saveAs ( f, opts ); 

 

main();

Here it is…

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 ,
Jun 13, 2017 Jun 13, 2017

Copy link to clipboard

Copied

Thank you again. I was actually in the middle of editing my second question as I was able to dig a little deeper and found that

f= Folder(app.activeDocument.path).saveDlg("Choose PDF output folder:");

would keep the file location the same as the original folder which is exactly what I needed for location.

Thank you for your time and wisdom! Still learning, slowly but surely.

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 21, 2022 Apr 21, 2022

Copy link to clipboard

Copied

Is there a way to adjust this script to have it just open a dialog box for my PDF presets so I can choose each time which I want to use?  Thanks in advance if someone could tweek 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
Participant ,
Apr 21, 2022 Apr 21, 2022

Copy link to clipboard

Copied

I just realized that what I'm actually asking for is to adjust the existing SaveDocsAsPDF script to do what I'm asking above.  Want it to be a batch "Save as" function.

 

Not sure if it's still relevant in this thread, if not please move to wherever or tell me where to move it.  Thanks!

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 22, 2022 Apr 22, 2022

Copy link to clipboard

Copied

LATEST

I made a new post called, "Modified Illustrator Script Needed for SaveDocsAsPDF" to address my request.  Please respond to that if anyone happens to see my previous comments on this thread, thanks!

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 ,
Jun 13, 2017 Jun 13, 2017

Copy link to clipboard

Copied

In fact it's even needless. If you need to save it to the exact location of the active document and given it's saved already, you could save directly with

doc.saveAs ( File ( app.activeDocument.fullName.replace ( /\.ait?$/i, "")+".pdf" ) );

hence avoiding the need of a dialog.

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 ,
Jun 14, 2017 Jun 14, 2017

Copy link to clipboard

Copied

That makes sense, we do occasionally need to save it in another folder as well so it's nice to have both options.

From what I've read, hotkeying a script to an action (Insert Menu Item) will reset every time Illustrator is restarted. There's no known workaround for this yet correct?

Thank you again!

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 ,
Sep 27, 2017 Sep 27, 2017

Copy link to clipboard

Copied

Hi

Can you please explain me what I am missing? Thanks

function main(){

    var doc =app.activeDocument;

    doc.saveAs ( File ( doc.fullName.replace ( /\.ait?$/i, "")+".pdf" ) );

}

"doc.fullName.replace is not a function"

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 ,
Jan 27, 2022 Jan 27, 2022

Copy link to clipboard

Copied

I know this is an ancient thread but I'm sure others will continue coming across this for years to come.

Searching for answers as to why the error

[...].replace is not a function

was thrown lead me here.  Is it possible the value in doc.fullName might be a number?

Per https://stackoverflow.com/questions/18862400/replace-is-not-a-function, replace is only a function of a String object; if the value might at any time be considered anything other than a string, encasing it as a String object should force the value to be interpreted as a string and therefore grant access to the String object's functions:

doc.saveAs ( File ( String(doc.fullName).replace ( /\.ait?$/i, "")+".pdf" ) );

 

Let us know if you find out otherwise.

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