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

Code/script to extract all text from Illustrator document?

Participant ,
Mar 30, 2015 Mar 30, 2015

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.

TOPICS
Scripting
2.7K
Translate
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

Guide , Mar 30, 2015 Mar 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);

        } 

    }

Translate
Adobe
Guide ,
Mar 30, 2015 Mar 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);

        } 

    }

Translate
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 ,
Mar 30, 2015 Mar 30, 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"
Translate
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
Guide ,
Mar 30, 2015 Mar 30, 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.

Translate
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 ,
Mar 30, 2015 Mar 30, 2015
LATEST

All the official Guides and References are vague, they have the bare minimum to get anyone started, they could be better, fortunately we have this forum and other pioneers (fellow users) who paved the road for the rest of us.

PageItem is what's called a Super Class, while the objects themselves are Classes. Classes inherit all properties from their parent Super Class, then add properties or methods particular to each individual Class.

Super Classes and Inheritance are very important Javascript concepts (not explained in the guides). One of their major advantages of using them is to avoid creating the same properties and methods for a number of similar objects.

For example (building the js API), if TextFrames, PathItems, PlacedItems, etc, all have Name, GeometricBounds, and Typename properties, instead of creating 3 objects, each with the same 3 properties (9 properties total), it is more convenient to create a super class PageItem, add these 3 properties, then create our 3 classes based on it that will share the same properties....then, continue adding properties particular to each class, like TextFrame.contents, PathItem.area, or PlacedItem.file

Translate
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