16 Replies Latest reply on Jul 12, 2017 3:50 AM by Test Screen Name

    Automating SaveAs Word docx

    Ian Proudfoot Level 3

      As part of a FrameMaker based publishing system that takes XML files then outputs PDF and optionally Word files, we have to improve the quality of the Word output. The previous process used FrameMaker's RTF output, but the results were not good enough without significant post processing. In an attempt to give the customer what they need I found that Acrobat's PDF output was good enough, so all we need to do is automate the process.

       

      My developer created a folder level JavaScript that converts the PDF file which almost does what we need. However it does give an error dialog which may or may not prevent the export of the Word document. Here is the JavaScript:

       

      /**
       * trustedPrint function: Exercise the print function in the privileged context
       * 
       * @param doc The Doc object of the target document
       * @param pparam The PrintParams object containing print settings
       */
      trustedSave = app.trustedFunction(
      function(input) {
      app.beginPriv();
      
      try
      {
      var rs = util.readFileIntoStream(input);
      var path = util.stringFromStream(rs);
      
      var oDoc = app.openDoc({
      cPath: path + ".pdf", 
      bHidden: true
      });
      oDoc.saveAs(path + ".docx", "com.adobe.acrobat.docx");
      oDoc.saveAs(path + ".done.pdf");
      oDoc.closeDoc();
      }
      catch(e)
      {
      console.println("[save2word] unable to process: " + input);
      for (var i in e)
      console.println( i + ": " + e[i]);
      }
      
      app.endPriv();
      }
      );
      
      trustedSave("/C/publiframe/api/pdf2word.txt");
      
      

      The path to pdf2word.txt provides a way to introduce the path for the source PDF file.

       

      When this is used we see an Acrobat dialog that tells us that a file cannot be found:

      AcroDCerror.png

      The JavaScript debugger tells us this, but what does it all mean? (The line numbers may not match the JavaScript above):

      Invalid Location "/C/Users/itproudfoot/AppData/Local/Temp/CIMP000102231_EN.word.pdf". File or folder does not exist.Exception in line 23 of function trustedSave<, script Folder-Level:App:save2word.js
      [save2word] unable to process: /C/publiframe/api/pdf2word.txt
      name: NotAllowedError
      message: Security settings prevent access to this property or method.
      extMessage: NotAllowedError: Security settings prevent access to this property or method.
      App.openDoc:23:Folder-Level:App:save2word.js
      
      
      fileName: Folder-Level:App:save2word.js
      lineNumber: 23
      number: 11
      columnNumber: 0
      

       

      Despite the error message the Word document is created correctly on my system. On the client's system and our test system the output fails.

      For business reasons this needs to work with AcrobatDC and Acrobat XI.

       

      I hope this is a simple error, and that we're not trying to do something that is not permitted.

      Thanks for any help.

      Ian