Skip to main content
Participant
Apr 6, 2017 5:49 AM UTC
Answered

Setting the bleed in AI via Javascript

Hi All,

I'm writing a function to change the artboard size and add bleed depending on certain conditions.

I can't actually believe this is causing me trouble but here it is, I'm trying to set the bleed dimensions in AI document with Javascript. All I've found so far is setting up PDF export options or print options, but not the actual artboard Document Setup. I just want to be able to set bleed to a newly created document like in this window:

So similar to Indesign:

with(myDocument.documentPreferences){

  documentBleedUniformSize = true;

  documentBleedTopOffset = 7;

  }

(CC2017)

yury_ostanin
yury_ostaninCorrect answer
Inspiring
Mar 23, 2018 5:14 PM UTC

Summarizing best solution by far: we can change bleed size using preinstalled plugin.

Windows

https://goo.gl/YE1Vah by tomr11694738​

Drop plugin in ProgramFiles\Adobe\Adobe Illustrator\Plug-ins\Extensions. Use following code to run it:

app.sendScriptMessage ("My_plugin_name", "mySelector", bleeds);

where bleeds is bleedoffset in points.

Mac

GitHub - ten-A/Bleed by Ten A​

All hail to these two dudes.

51 replies

Egor Chistyakov
Inspiring
Jul 17, 2025 4:26 AM UTC

Even though a solution exists, we need a simple way to access theese.

Here’s a user request you can upvote if you agree: http://illustrator.uservoice.com/forums/908050/suggestions/50205060

Translate
TySprice
Inspiring
Jul 19, 2025 1:36 AM UTC

Yes, definitely wish it was baked into extendscript and we didn't have to go to such ends to modify bleed. The bleed Plugin does not work on Apple Silicon macs so the hacky way of doing things by no means covers all the bases. It is really less and less of a solution as time goes by.

Translate
TySprice
Inspiring
Jun 23, 2025 9:11 PM UTC

For anyone currently attempting to do this on a Mac. This link worked for me. Huge thanks to @Ten A 

https://github.com/ten-A/Bleed 

 

I also had to un-quarantine the plugin and followed the instructions in this link to do so.

 

https://www.motunation.com/forum/viewtopic.php?t=72872 

 

First copied the plugin into the plugins folder within the Illustrator application folder. Ran Illustrator once, let it complain then quit Illustrator. Then followed the steps in the second link to un-quarantine the plugin. Now works like a charm.

Translate
Stanly Hoffman
Known Participant
Apr 27, 2019 8:19 PM UTC

Tried to make 1.5 mm bleeds offset and got 1.411 mm... As well I can't make 1.5 pts offset, its always rounds it to 1. So plugin rounds the values by points, needs to be fixed.

Translate
Stanly Hoffman
Known Participant
Apr 29, 2019 9:29 PM UTC

This one did the job for 1.5 mm offset: app.sendScriptMessage ("My_plugin_name", "mySelector", "4,252"); 

Thank you, tomr11694738.

Translate
yury_ostanin
yury_ostaninCorrect answer
Inspiring
Mar 23, 2018 5:14 PM UTC

Summarizing best solution by far: we can change bleed size using preinstalled plugin.

Windows

https://goo.gl/YE1Vah by tomr11694738​

Drop plugin in ProgramFiles\Adobe\Adobe Illustrator\Plug-ins\Extensions. Use following code to run it:

app.sendScriptMessage ("My_plugin_name", "mySelector", bleeds);

where bleeds is bleedoffset in points.

Mac

GitHub - ten-A/Bleed by Ten A​

All hail to these two dudes.

Translate
Ten A
Community Expert
Community Expert
Mar 23, 2018 11:20 PM UTC

Here is a sample build for AI(Macintosh) ver.21 and later. You can download from the アプリケーション自動化総合コミュニティフォーラム (Japan) .

Bleed.aip.zip

Commentary also available in [AI]Javascriptの機能を拡張する方法 (Sorry, its a Japanese article. However, you can translate via google...)

Translate
Participant
May 2, 2019 7:31 PM UTC

Just writing a note about this one. This plugin worked on Illustrator CC 2019 on Mac OS X 10.14.4.

Instructions:

1. Download and unzip Bleed.aip.zip mentioned here (or clone from github and compile. fun.)

2. Place the resulting Bleed.aip plugin to folder /Applications/Adobe Illustrator CC 2019/Plug-ins.localized/Extensions

3. Write a driver Javascript as follows:

$ cat script.js
   alert (setBleed ( 51.0236 ));  // unit: pt; range: 0-72.0

function  setBleed (n) {
       var  result = app.sendScriptMessage ( 'Bleed', 'Bleed' , n);
       return  result;
}

4. Start Illustrator

5. Select menu File -> Scripts -> Other Script ...

6. Select the script you wrote on step #3

All this information has been available on this thread or linked threads. However, the exact needed steps seemed to be a bit scattered, so I thought writing this down will save my effort next time I'm having this problem.

Great thanks to the guys who took the effort to produce this plugin!

Translate
Inspiring
Apr 17, 2017 2:09 PM UTC

Another possible way with script:

- Save document uncompressed so that we can parse the bleed data, and close it.

- Open and read the saved file, use this regex to replace the bleed value: ([\d.]*)(?= /Real \(Bleed(Left|Right|Top|Bottom)Value\))
, then save it. Note that the bleed value are in point unit.

- Now the bleed changed, open it in Illustrator again, and save it compressed if needed.

Translate
Silly-V
Legend
Oct 31, 2017 6:27 AM UTC

I changed your regexp to this because it was putting my bleed single-digit value in 2x:

/((\d{1,2}))(?= \/Real \(Bleed(Left|Right|Top|Bottom)Value\))/g

Here is the function:

function setBleed(doc, bleed, newName){

  /*

    Thanks to moluapple.

    bleed in points

  */

  var opts = new IllustratorSaveOptions();

  opts.compressed = false;

  opts.pdfCompatible = false;

  doc.saveAs(File(newName), opts);

  var f = app.activeDocument.fullName;

  var contents;

  f.open('r');

  contents = f.read();

  f.close();

  contents = contents.replace(/((\d{1,2}))(?= \/Real \(Bleed(Left|Right|Top|Bottom)Value\))/g, bleed);

  f.open('w');

  f.write(contents);

  f.close();

  app.activeDocument.close();

  app.open(f);

  var opts2 = new IllustratorSaveOptions();

  opts2.compressed = true;

  opts2.pdfCompatible = true;

  app.activeDocument.saveAs(app.activeDocument.fullName, opts2);

}

Translate
Participating Frequently
Jun 20, 2018 10:10 PM UTC

I'm having trouble getting this function mentioned above to work (I marked where it fails) :

function setBleed(doc, bleed, newName){ 

  /*

    Thanks to moluapple.

    bleed in points

  */ 

  var opts = new IllustratorSaveOptions(); 

  opts.compressed = false; 

  opts.pdfCompatible = false; 

  doc.saveAs(File(newName), opts); 

  var f = app.activeDocument.fullName; 

  var contents; 

  f.open('r'); 

  contents = f.read(); 

  f.close(); 

  contents = contents.replace(/((\d{1,2}))(?= \/Real \(Bleed(Left|Right|Top|Bottom)Value\))/g, bleed); 

  f.open('w'); 

  f.write(contents); 

  f.close(); 

  app.activeDocument.close();

//THIS IS WHERE IT FAILS 

  app.open(f); 

  var opts2 = new IllustratorSaveOptions(); 

  opts2.compressed = true; 

  opts2.pdfCompatible = true; 

  app.activeDocument.saveAs(app.activeDocument.fullName, opts2); 

} 

Did this work for you? I couldn't get this to work, and I can't use a plug-in for my script since the script will eventually be run on someone else's computer. If this solution ended up working for anyone then I might keep toying around with it to see if I can get it to work. When I run it Illustrator says that the new file is in an unknown format and so won't load. I get this problem essentially anytime I try to write to an illustrator file.

Translate
Inspiring
Apr 15, 2017 10:29 PM UTC

Matts, do you have Windows system? I can try to make a Win plugin which can be used by your script.

Well, to be honest, I made the one for testing purpose.The plugin sets bleeds from txt file.

You write some number to txt file with  script, run action, bleeds change - voila.

But if you don't have win system, there's no point uploading this plugin.

Translate
Silly-V
Legend
Apr 16, 2017 7:09 AM UTC

What is a difference which would make your plugin Windows-only? To make it for Macs, would the entire code need to be re-written, or only certain parts?

Translate
Inspiring
Apr 16, 2017 2:13 PM UTC

The difference is I can compile for Windows only

But the C++ code for Mac should be the same.

The meaningful part of code is below.

int bleedOffset; //let the bleed be integer, why not

    ifstream infile ("C:\\Tom_Subscriber\\data.txt"); //read the number from txt file. It's presumed that JS script has already written  the number into it;

    infile >> bleedOffset;

  

    AIRealRect myRect;

//lets make bleeds symmetrical

    myRect.right = bleedOffset;

    myRect.left = bleedOffset;

    myRect.top = bleedOffset;

    myRect.bottom = bleedOffset;

    error = sAIDocument->SetDocumentBleeds (myRect); // command to set bleeds.

As you can see, there's no dialog, input from txt file.

The plugin adds a command to the Objects menu.

Translate
Participant
Apr 13, 2017 5:42 AM UTC

Bump,

Is there really no way to do this?

Translate
Silly-V
Legend
Apr 13, 2017 2:31 PM UTC

We must not give up the search

Translate
Silly-V
Legend
Apr 6, 2017 7:57 AM UTC

That's a good question, I can't find it!

Translate
CarlosCanto
Community Expert
Community Expert
Apr 7, 2017 7:12 AM UTC

Save as PDF with Bleed...then re Save as Ai

 

[edit: please ignore, I should have tested it before posting]

Translate
Participant
Apr 10, 2017 2:08 AM UTC

Yes, problem is even setting it up for pdf export does absolutely nothing.

var dest = "~/Desktop/testme1.pdf";

var doc = app.activeDocument;

var myFile = new File(dest);

var saveOpts;

setSaveOptions();

saveFileToPDF(myFile);

function saveFileToPDF(myFile){

    var originalInteractionLevel = userInteractionLevel;     

    userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;  

    doc.saveAs(myFile,saveOpts);    

    userInteractionLevel = originalInteractionLevel;    

}

function setSaveOptions(){

    saveOpts = new PDFSaveOptions();

    saveOpts.compatibility = PDFCompatibility.ACROBAT5;

    saveOpts.generateThumbnails = true;

    saveOpts.optimization = true;

    saveOpts.preserveEditability = true;

    saveOpts.bleedOffsetRect = [2,2,2,2];

    saveOpts.trimMarks = true;

}

After this media box is the size of trim marks but the art is cropped to the Artboard size, (not +2).

Translate