Skip to main content
Known Participant
June 15, 2018
Question

Trouble with VBA script to automate Illustrator to get and loop through all textFrames

  • June 15, 2018
  • 2 replies
  • 877 views

I wrote the following code to get and loop through all the textFrames in a pdf opened in Illustrator:

Sub editPDF(filePath As String)

    Dim iapp As New Illustrator.Application

    Dim idoc As Illustrator.Document

    Dim pdfText As String

  

    With iapp.Preferences.pdfFileOptions

        .PageToOpen = 1

    End With

  

    iapp.UserInteractionLevel = aiDontDisplayAlerts

  

    Set idoc = iapp.Open(filePath)

    Set idoc = iapp.ActiveDocument

  

    Set myTextFrames = idoc.TextFrames

      

    For Each TextFrame In idoc.TextFrames

  

        pdfText = TextFrame.Contents

      

        MsgBox (pdfText)

          

    Next

    

    idoc.Close

    Set idoc = Nothing

    Set iapp = Nothing

End Sub

However, when I run this code some of the textFrames are inexplicably not included in the collection list idoc.TextFrames.  The file only has a single layer.  The one thing I can think of is that the files that I am opening include fonts that I don't have installed on my workstation (this will be corrected soon).  But some of the textFrames that use the bad fonts DO show up in this list, so I am very confused.

This topic has been closed for replies.

2 replies

Silly-V
Legend
June 15, 2018

What kind of PDF are you opening? Is it a PDF which was previously exported with a PDF-X standard, or generated by other software which may have text outlined? Are the text frames modern text frames, or are they actually legacy text items, which are a different object as far as scripting goes?

Larry G. Schneider
Community Expert
Community Expert
June 15, 2018

Any relation between Area/Point text and which text frames are chosen? Are any of the text frames part of a group?