Skip to main content
Participant
July 14, 2025
Answered

Help with Illustrator script to embed ALL linked items

  • July 14, 2025
  • 3 replies
  • 1986 views

Hi everyone! I'm a graphic designer trying to create a JavaScript script for Adobe Illustrator to automatically embed all linked images.

The Problem

I often work with files that contain a large number of linked images. When I need to send a PDF with everything embedded, I have to manually embed each image—sometimes clicking hundreds of times. It's extremely tedious.

I know I can Shift-click all the linked items and choose Links panel menu > Embed Image(s), but Illustrator prompts a confirmation for each individual image, which defeats the purpose.

There must be a more efficient and less painful way to do this.

The Approach

With the help of ChatGPT, I've tried several versions of a script that loop through all placedItems and call .embed() on them. However, they all produce the same issue:

  • Only some images (like every other one) get embedded.

  • Some images change size or shift position after being embedded.

I’ve attached screenshots showing the inconsistency. Any ideas why this is happening or how to fix it?

Thanks in advance!

if (app.documents.length > 0) {
    var doc = app.activeDocument;
    var linkedItems = doc.placedItems;
    var count = 0;

    for (var i = 0; i < linkedItems.length; i++) {
        var item = linkedItems[i];
        if (!item.embedded) {
            try {
                item.embed();
                count++;
            } catch (e) {
                alert("No se pudo incrustar el elemento: " + item.file.name + "\nError: " + e);
            }
        }
    }

    alert("Se incrustaron " + count + " elementos enlazados.");
} else {
    alert("No hay documentos abiertos.");
}



Correct answer Kurt Gold

An additional note: If you save your Illustrator document as .ai you can turn on the "Include Linked Files" checkbox in the Illustrator Options dialog to embed all linked files in one go.

 

You then just have to close and reopen the document to get the version with the embedded files.

3 replies

Kurt Gold
Community Expert
Kurt GoldCommunity ExpertCorrect answer
Community Expert
July 15, 2025

An additional note: If you save your Illustrator document as .ai you can turn on the "Include Linked Files" checkbox in the Illustrator Options dialog to embed all linked files in one go.

 

You then just have to close and reopen the document to get the version with the embedded files.

CarlosCanto
Community Expert
Community Expert
July 16, 2025

awesome tip, I learned something today.

Inspiring
July 15, 2025

Perhaps I'm missing something, but why would you write a script to do this?

 

Illustrator already embeds all the images when you save as a PDF.

 

If the problem is that you want the original resolution/format, you can change the PDF options when you export so that the images are not resampled.

CarlosCanto
Community Expert
Community Expert
July 15, 2025

That's what I thought, but I've heard from a couple of clients they're having the same issue of missing linked images in the final pdf.

 

I have not seen this problem personally.

Inspiring
July 15, 2025

If this is the case, then I would look for clipping mask problems or image format problems.

 

It would be useful to have a problem PDF to analyze.

One could also save as a PDF with no compression, open the result to verify that all is well and re-save as a new PDF without compression.

This would still be much easier than writing a script.

CarlosCanto
Community Expert
Community Expert
July 14, 2025

you need to start embedding from the bottom up. After each iteration the next item gets the previous items index, ie second item (index 1) will become index 0 after the first item (index 0) gets embedded. 

 

this line reverses the process order

for (var i = linkedItems.length-1; i>=0; i--) {

 

full script

if (app.documents.length > 0) {
    var doc = app.activeDocument;
    var linkedItems = doc.placedItems;
    var count = 0;

    // for (var i = 0; i < linkedItems.length; i++) {
    for (var i = linkedItems.length-1; i>=0; i--) {
        var item = linkedItems[i];
        if (!item.embedded) {
            try {
                item.embed();
                count++;
            } catch (e) {
                alert("No se pudo incrustar el elemento: " + item.file.name + "\nError: " + e);
            }
        }
    }

    alert("Se incrustaron " + count + " elementos enlazados.");
} else {
    alert("No hay documentos abiertos.");
}

 

Inspiring
July 15, 2025

In addition to my other answer, I would like to recommend ChatGPT. The documentation is so spread out and confusing that it can be hard to advance. ChatGPT has helped me enormously in the last few months in spotting bugs, explaining what is possible or not, and how all the different parts function together.