2 Replies Latest reply on Jun 29, 2010 9:42 AM by Marco Lugli

    Save AS prompt window Confirmation

    Marco Lugli Level 1


      I would like to go through all the steps involved in the process of exporting one document to XHTML in Indesign CS3.

      I found a scripting block on this forum by Dave Saunders which illustrate how to interact with a menu action.

      The fact is that when the action takes place, then Indesign CS3 prompts for a "Save As" window before continuing.

      Is there a way to bypass this thing or maybe to script the confirmation (along with new name of file) of this window?

      Here is Dave Saunders code:


      var outputFile = File("D:\\test.xhtml");
      var document = app.activeDocument;
      var mainMenu = app.menus[0];
      var fileMenu = mainMenu.submenus.item("File");
      var xMediaItem = fileMenu.menuElements.item("Cross-media Export");
      var xPortItem = xMediaItem.menuItems.item("XHTML / Dreamweaver...");
      var action = xPortItem.associatedMenuAction;




        • 1. Re: Save AS prompt window Confirmation
          Kasyan Servetsky Level 5

          Here is what I found in my archive a sample script by Roey Horns (I just had to modify one line to make it work).

          The XHTML export feature is provided by a script, so the objects/properties/methods do not appear in the InDesign scripting object model. But you can use the script from another script, as shown in the example script below (graciously provided by Roey Horns, who wrote the export script).

          // Export as XHTML sample script 
          // Preparation 
          // we require the DOM from version 5.0 
          app.scriptPreferences.version = 5.0           
          // replace this with the paths to your files 
          var outputFile = File('~/Desktop/test.html'); 
          var documentToExport = File('~/Desktop/Test.indd'); 
          // open the document 
          var document = app.open(documentToExport, false); 
          // 1. Step: Load the script 
          var scriptPath = Folder.startup + ((File.fs == "Macintosh") ? '/../../../Scripts/Export as XHTML/' : '/Scripts/Export as XHTML/'); 
          var scriptFile = File(scriptPath + 'XHTMLExport.jsxbin'); 
          if (scriptFile.exists) { 
               var script = scriptFile.read(); 
               scriptFile.close();      // execute the loaded script 
               // this declares the classes and variables defined in the script file within our scope 
          // 2. Step: Set up options for the export 
               // The main xhtml export options are stored in a special label of the document. 
               // Use the XHTMLExportOptions class to read, change and save them back to the 
               // document. Saving the options back is not required for the options to be in 
               // effect for the export -- with the exception of the exportForWebPreferences 
               // (see below).      // To get a new instance of XHTMLExportOptions you can either load the options 
               // from a document using the class method 
               var opts = XHTMLExportOptions.restore(document);
               // or you can create a new instance with default values using the constructor:      var opts = new XHTMLExportOptions();      // Change the options to your liking: 
               //     .numberedListsPolicy 
               //          enum determining how numbered lists are represented in the resulting XHTML 
               //          possible values: 
               //               XHTMLExportOptions.regularOrderedListItems     (default) 
               //               XHTMLExportOptions.fixedListItems 
               //               XHTMLExportOptions.convertToText 
               //     .bulletedListsPolicy 
               //          enum determining how bulleted lists are represented in the resulting XHTML 
               //          possible values: 
               //               XHTMLExportOptions.regularUnorderedListItems     (default) 
               //               XHTMLExportOptions.convertBulletsToText 
               //     .styleHandling 
               //          enum determining how to handle styles 
               //          possible values: 
               //               XHTMLExportOptions.emptyStyles          (default) 
               //               XHTMLExportOptions.noStyles 
               //               XHTMLExportOptions.extStyleSheet 
               //     .styleSheet 
               //          string: URL of external style sheet 
               //          default: "" 
               //     .linkToJavaScript 
               //          boolean determining whether to include a link to the javascript file below 
               //          default value: false 
               //     .javaScriptURL 
               //          string: URL of javascript file to link to 
               //          default: ""      
               opts.styleHandling = XHTMLExportOptions.extStyleSheet; 
               opts.styleSheet = 'styles/default.css';      
               //     The following two properties of XHTMLExportOptions override the properties 
               // copyOriginalImages, copyFormattedImages and copyOptimizedImages on  
               //     app.exportForWebPreferences: 
               // .imageHandling 
               //          enum determining how images are handled 
               //          possible values: 
               //               XHTMLExportOptions.copyOriginal 
               //               XHTMLExportOptions.copyOptimized     (default) 
               //               XHTMLExportOptions.linkToServerPath 
               //     .formatted 
               //          boolean determining if optimized images should be formatted as in ID 
               //          default value: false 
               //     .serverPath 
               //          string: URL of images folder on server 
               //          default = "" 
               //     .imageExtension 
               //          string: extension to be used for images 
               //          default: ".jpg"      opts.formatted = true;      // Use the properties of app.exportForWebPreferences to specify how to 
               // optimize web images 
               // Notice that the properties copyOriginalImages, copyFormattedImages and  
               // copyOptimizedImages are being overriden by the imageHandling setting 
               // as explained above      app.exportForWebPreferences.gifOptionsInterlaced = true;      
               // If you want to save the options in the document you can use the persist 
               // funtion on the XHTMLExportOptions object: 
               //          opts.persist(document); 
          // 3. Step: Do the export 
               // Create an XHTMLExporter instance 
               // You need to pass a File object pointing to the script file into the 
               // constructor so that XHTMLExport can find its ancillary files 
               var exporter = new XHTMLExporter(scriptFile); 
               // call its doExport(document, items, options, outputFile) method 
               // parameters; 
               //          document 
               //               the document to export from 
               //          list 
               //               optional list of page items in document to export. If empty or undefined 
               //               doExport will export all page items on visible layers on all spreads 
               //               of the document (exception: TOC and Index stories are skipped) 
               //          opts 
               //               the XHTMLExport options to use 
               //          outputFile 
               //               the File to export to. Will get overridden if it already exists 
               var success = exporter.doExport(document, undefined, opts, outputFile);      
               // check the results: 
               if(success) { 
                    // even though the export has succeeded there may have been warnings: 
                    //           exporter.missingImageLinks is an array of File objects of the links that were missing 
                    //           exporter.outOfDateLinks is an array of File objects of the links that were out of date 
                    //          exporter.numImagesDroppedOut is the number of pasted images that were not exported 
                    //           exporter.stockPhotoComps is an array of File objects of the stock photo comps that were exported 
                    //           exporter.missingMovieLinkss is an array of File objects of the movies that were missing 
                    //          exporter.numMoviesDroppedOut is the number of movie files that were not exported 
                    if(exporter.outOfDateLinks.length > 0) { 
                         alert('Exporting ' + document.name + ' succeeded\nHowever ' + exporter.outOfDateLinks.length + ' links were out of date.'); 
               } else { 
                    // the error property holds the error object that made the export fail 
                    alert('Exporting ' + document.name + ' failed with this error message:\n' + exporter.error.message); 
          } // if (scriptFile.exists) 
          // 4. Step: Cleanup 
          // close the document 
          1 person found this helpful
          • 2. Re: Save AS prompt window Confirmation
            Marco Lugli Level 1

            Thank you very much Kasyan - Your answer was very clear and exhaustive.

            I successfully exported my Indesign document to Html.