Skip to main content
Inspiring
March 30, 2015
Answered

Code/script to extract all text from Illustrator document?

  • March 30, 2015
  • 1 reply
  • 2682 views

Anyone have code/script for this or know how to create code to extract all the text off an active document in Illustrator. Extract text as in text for any & all text items in the document (TextFrameItem, TextRange, TextPath, etc.). We can just dump the text with alerts().

What I'm not sure of is what order or hierarchy to extract the text. Where do we start from activeDocument.textFrameItems/TextRanges/etc. How are text organized in Illustrator? I'm new to Illustrator scripting.

This topic has been closed for replies.
Correct answer Qwertyfly___

Something as simple as this may do the trick.

this will act on all open documents.

you could then create a file and write to that rather then just alert

for(var i = 0; i < app.documents.length; i++){ 

    for(var j = 0; j < app.documents.textFrames.length; j++){ 

        var str = app.documents.textFrames.contents; 

        alert(str);

        } 

    }

1 reply

Qwertyfly___
Qwertyfly___Correct answer
Legend
March 30, 2015

Something as simple as this may do the trick.

this will act on all open documents.

you could then create a file and write to that rather then just alert

for(var i = 0; i < app.documents.length; i++){ 

    for(var j = 0; j < app.documents.textFrames.length; j++){ 

        var str = app.documents.textFrames.contents; 

        alert(str);

        } 

    }

man9ar00Author
Inspiring
March 31, 2015

Thanks, your comment got me to review my script code & fixed some issues below to get it working.

  • I got confused by the Illustrator CS6 scripting reference where they refer to text frames as TextFrameItems and TextFrameItem (as the item/object section heading in the document) yet in the code samples in those sections it's like app.activeDocument.textFrames and textFrame. We find no such deviation with page items and path items. Adobe's documentation seems to have made it more confusing, should have just named the section TextFrames and TextFrame, leaving out the item part. I initially had item(s) in the collection/property name, just took it off after noticing this difference.
  • referenced the contents property as "content"
Qwertyfly___
Legend
March 31, 2015

Glad I could help.

The documentation is not great.

I find it quite frustrating.

then I try to modify the software here at work and realize that the adobe documentation, While not great, is a hell of a lot better then the completely out of date crap I'm forced to sort through.