Skip to main content
Inspiring
October 3, 2022
Answered

Unlock page items that come from master pages

  • October 3, 2022
  • 1 reply
  • 610 views

I'm working on a project for a PDF document that is also need to be accessible to screen reader users. The document has a folio for some additional information such as the company and department names and the page number.

 

To solve this problem, I'm working on a script to automatically convert all text in the folio to outline. It turns out that all items on master pages are normally locked to the work page (and locked in a way that cannot be identified by a simple if (item.locked == true).

 

When I manually unlock the item on the page (cmd + shift + right click on the item) the script works perfectly.

 

How can I also automate the unlocking of all these items on each of the document pages?

This topic has been closed for replies.
Correct answer Monomotor

I just figured out that first I have to apply the overrides for all the master pages text elements and then look for the items with the desired paragraph style to create the outlines.

 

This code is working for my purpose:

var myDoc = app.activeDocument

// Override text frames from master pages
for (var i = 0; i < myDoc.pages.length; i++) {
  // var page = myDoc.pages[i]
  var myItems = myDoc.pages[i].appliedMaster.pageItems.everyItem().getElements()

  for (var j = 0; j < myItems.length; j++) {
    if (myItems[j] instanceof TextFrame) {
      try {
        var item = myItems[j]
        item.override(myDoc.pages[i])
      }
      catch(e) {}
      }
    }
 }

// Create outlines for items of a specific paragraph style
var style = myDoc.paragraphStyleGroups.item("group-name").paragraphStyles.item("style-name")
app.findTextPreferences.appliedParagraphStyle = style

var found = myDoc.findText()
if (found.length > 0) {
  for (var i = 0; i < found.length; i++) {
    found[i].createOutlines()
  }
}

1 reply

brian_p_dts
Community Expert
Community Expert
October 3, 2022

You need to use var overriddenItem = item.override(targetPage);

MonomotorAuthor
Inspiring
October 3, 2022

Thank you, @brian_p_dts. I'm not sure how to use this on my code, can you please help me?

 

var myDoc = app.activeDocument

// get the style for the items that need to be converted to outlines
var folioStyle = myDoc.paragraphStyleGroups.item("pagina").paragraphStyles.item("folio")

// set the style at the Find Text Preferences
app.findTextPreferences.appliedParagraphStyle = folioStyle

// get the items
var found = myDoc.findText()

if (found.length > 0) {
  // for each item found
  for (var i = 0; i < found.length; i++) {
    // convert text to outlines
    found[i].createOutlines()
  }
}

 

MonomotorAuthorCorrect answer
Inspiring
October 3, 2022

I just figured out that first I have to apply the overrides for all the master pages text elements and then look for the items with the desired paragraph style to create the outlines.

 

This code is working for my purpose:

var myDoc = app.activeDocument

// Override text frames from master pages
for (var i = 0; i < myDoc.pages.length; i++) {
  // var page = myDoc.pages[i]
  var myItems = myDoc.pages[i].appliedMaster.pageItems.everyItem().getElements()

  for (var j = 0; j < myItems.length; j++) {
    if (myItems[j] instanceof TextFrame) {
      try {
        var item = myItems[j]
        item.override(myDoc.pages[i])
      }
      catch(e) {}
      }
    }
 }

// Create outlines for items of a specific paragraph style
var style = myDoc.paragraphStyleGroups.item("group-name").paragraphStyles.item("style-name")
app.findTextPreferences.appliedParagraphStyle = style

var found = myDoc.findText()
if (found.length > 0) {
  for (var i = 0; i < found.length; i++) {
    found[i].createOutlines()
  }
}