2 Replies Latest reply on Sep 23, 2016 6:37 AM by Pickory

    Export to HTML (and Text Variables) broken for Master Pages. JS solution

    TonightWeDineInHELL Level 1

      Hi, I thought I'd post my solution to this weird little InDesign glitch. It's not elegant, but it worked.

      I needed to export a rather large InDesign-document as HTML and then loop through it with javaScript to put it's contents into SQL.  The problem was, none of the information in the Master Pages will export as HTML. I then tried to "Override"  the Master Pages in the Pages panel, and while this did make the Master Page items appear in the HTML export, the resulting code was a mess. (And by that, I mean way to messy to loop through using javaScript)  So,  I turned to javaScript inside InDesign. This led to further problems as Section Markers and Text Variables will not export as HTML either.

      So, I created text boxes on EVERY page to contain the information I needed to get from the Master Pages. Then I created the following script in the Scripts Panel:


      //select the document

      var myDocument = app.activeDocument;

      //get the page numbers

      var allPages = myDocument.pages.everyItem().name;


      //loop through the pages

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


      //get the Section name from the Section Marker applied to the page's Master Page.

      var section = myPage.appliedSection.marker;


      //get the Topic name from the applied Master page

      var topic = myPage.appliedMaster.textFrames.item("topic").contents;


      //get the Category name from the Master page that is applied to the the Master page and render the Text Variable into regular text that will export as HTML

      var category = myPage.appliedMaster.appliedMaster.textFrames.item("category").textVariableInstances[0].r esultText;


      //get the Book name from the Master page's applied Master page's applied Master page and render the Text Variable into regular text that will export as HTMl

      var book = myPage.appliedMaster.appliedMaster.appliedMaster.textFrames.item("book").textVariableInst ances[0].resultText;


      // the text boxes where the results will be put - These text boxes are 'named' by opening their Layer in the Layers Pallet (click the little triangle) then clicking on each text boxes sublayer and changing it's name from something like <text frame> to something like "c_book"

      var copyBook = myPage.textFrames.item("c_book");

      var copySection = myPage.textFrames.item("c_section");

      var copyCategory = myPage.textFrames.item("c_category");

      var copyTopic = myPage.textFrames.item("c_topic");


      //then place the info into those text boxes like so

      copyBook.contents = book;

      copySection.contents = section;

      copyCategory.contents = category;

      copyTopic.contents = topic