3 Replies Latest reply on Jul 27, 2011 7:51 AM by private razor

    Acrobat reader print with javascript script

    CAXOnline

      Hello,

       

      I read the documentation for printing silently using javascript, but it does not work as not all COM objects are installed.

      A code example:

       

      <body>

      <object id="examplePDF" data="DFWCRT133735.PDF" type="application/pdf" title="SamplePdf" width="100%" height="100%">
         Your browser does not support PDF, Please install Adobe Acrobat.
      </object>
      <div id="pdfprop">
      </div>
      <script type="text/javascript">

          var pdf = document.getElementById("examplePDF");
          var divProps = document.getElementById("pdfprop");
         
          if (pdf) {

      // Attempt 1: Works, but shown printing dialig which I do not want
      //        pdf.print();

       

      // Attempt 2: Does not work. Shows an exception about parameters when printing
              //var printParms = { bUI: false, bSilent: true, bShrinkToFit: true };
              //pdf.print(printParms);

       

      // Attempt 3: Does not work as can't instatiate unexistent progid, class AcroExch.PDDoc. COM object is not registered

              var srcDoc = new ActiveXObject("AcroExch.PDDoc");
              var jsObj = srcDoc.GetJSObject();
              var pp = jsObj.getPrintParams();
              pp.interactive = pp.constants.interactionLevel.automatic;
              pdf.print(pp);
          }

      </script>
      </body>

      I read in google something about the Acrobat Pro version will have the missing COM object, but I can't force all my clients to buy that product. Is it possible with the reader version.

       

      I'll appreciate any help.

        • 1. Re: Acrobat reader print with javascript script
          private razor

          What version of Reader are you using? The reason I ask is because starting with Reader 7, the print function is deemed privileged. Reader 8 enforced the rule such that the code cannot be run from the server. You will have to install the code in the Javascripts folder within the Acrobat or Reader (in that order of preference) and call the code from Acrobat.

          • 2. Re: Acrobat reader print with javascript script
            CAXOnline Level 1

            I am trying with Reader 9.

            I am not trying to print from the server. The printing will happen on the client computers that is why I am trying to print using javascript from an html page. My clients do have different versions of Reader from 6 to latest

            Is there any way to achieve it with out installing anything else on the computers?

             

            Thanks,

            • 3. Re: Acrobat reader print with javascript script
              private razor Level 1

              You are running the print code from the browser (even though it is javascript). The point is - you cannot run privileged functions from the browser. You can call it if it resides in client machine. I went through this issue back in 2008 when Adobe enforced this rule with Reader 8. I did plenty of research and picked a lot of smarter brains, but the only solution I found was to put the JS code in the client device. If that is not possible, I would forget about silent printing and let users go through the hassle of pushing the print button. I will be more than interested if you find a solution around this.