2 Replies Latest reply on Mar 17, 2010 3:22 PM by ScottPrentice

    How to print a HTMLLoader?

    elweilando

      Hey!

       

      I want to load a htmlstring into a new htmlloader-object and print it via  window.runtime.flash.printing.

      unfortunately, my printer prints only blank pages.

       

      air tells me that  "Error #2057: The page could not be added to the print job" occured.

       

      Does anybody know how i can load html-content into a air-window and how i can send the content to the printer?

       

      My code in air is

       

      var pjob = new window.runtime.flash.printing.PrintJob;

      var options = new air.NativeWindowInitOptions();

      options.systemChrome = "none";

      options.type = "lightweight";

      var windowBounds = new air.Rectangle(200,250,300,400);

      var htmlStr = "<html><body>Hello <b>world</b>.</body></html>";

       

      newHTMLLoader = air.HTMLLoader.createRootWindow(true, options, true, windowBounds);

      newHTMLLoader.loadString(htmlStr);

      if (pjob.start()) {

      var poptions = new window.runtime.flash.printing.PrintJobOptions;

      poptions.printAsBitmap = true;

       

      try {                pjob.addPage(newHTMLLoader.htmlLoader, null, poptions);

      }            catch (e) {

      air.trace(e);

      }

      try {                pjob.send();

      }            catch (err) {

      air.trace(err);           }

      }      else {           air.trace("PrintJob couldn't start");      }

        • 1. Re: How to print a HTMLLoader?
          Dragos GEORGITA Adobe Employee

          Hi,

           

           

          This is a function that does printing of some HTMLLoader content. It scales the content via the CSS zoom property and than scales it back to 25% in order to improve the quality:

           

          function printer(){
               // create PrintJob object
               var html = new air.HTMLLoader()
               var container = new runtime.flash.display.Sprite();
               html.width = 2400;
               html.height = 1600;
               html.addEventListener(air.Event.COMPLETE, function(){
                         html.scaleX = 0.25;
                         html.scaleY = 0.25;
                         container.addChild(html);

                         var printjob = new air.PrintJob();

                         if (printjob.start()) {
                               try {
                                   var windowBounds = new air.Rectangle(0,0,600,400);
                                   printjob.addPage(container,windowBounds);
                               }catch(e) {
                                   air.trace("Error: " + e.message + " Detail: " + e.details + " Operation: " + e.operation)
                               }
                               printjob.send()
                         }
                     })
               html.loadString(’<div style="font-size:14px; font-weight:bold; zoom:400%">This is a printing test</div>’)
          }

           

          Hope this helps,

          Best regards,

          Dragos Georgita | Adobe AIR Engineering

          • 2. Re: How to print a HTMLLoader?
            ScottPrentice Level 4

            From what I'm seeing, this is still printing HTML as a bitmap. I was under the impression that in AIR 2 this would be fixed to print as "text" (vectors). Am I missing something (I'm hoping that I am).

             

            Thanks!

             

            ...scott