8 Replies Latest reply: Apr 20, 2011 10:01 PM by Flex harUI RSS

    FlexPrintJob produces print output missing large blocks of text

    JoshBeall Community Member

      Hi All,

       

      I'm using FlexPrintJob to generate print output from a Flex app.  I'm allowing the user to print off the "thank you" view of our app.  Here's the code that fires when the "Print" button is clicked in my app:

       

      var printer:FlexPrintJob = new FlexPrintJob();
      printer.printAsBitmap = false;
      // Display the print dialog to the user.  If they choose a printer
      // and click "print", this method will return true, and we will
      // spool the job to the printer they selected. If they hit cancel,
      // this method will return false, and we will not attempt to send
      // anything to the printer.
      if(printer.start()){
           printer.addObject(itemsToPrintContainer);
           printer.send();
      }
      

       

       

      itemsToPrintContainer is fairly text-heavy, and contains all the information that the user has entered so far, along with some "fine print" courtesy of our legal department :-)  Depending on the options the user chose and how much they typed, this will run between 1.25 pages, and a full two pages of print output (when printed to 8.5"x11" paper with a 1" top, bottom, and side margin).

       

      Something very strange is happening, however.  Only the first two-thirds of the text are printed.  All the text after that is missing, even though it is present in the view.  Additionally, the horizontal rules that separate different blocks of text are present, and are spaced appropriately.  E.g., if there is a long block of text missing, the space between the horizontal rules is exactly appropriate to fit that long block of text, even though it's not displayed.  Similarly, where there are short blocks of text missing, the space between the horizontal rules is appropriate to fit that short block of text.

       

      The horizontal rules are a simple component I created to draw a horizontal line.  Looks like this:

       

           <s:stroke>
                <s:SolidColorStroke color="{color}" weight="{weight}" alpha="{ruleAlpha}"/>
           </s:stroke>
      

       

      After some experimenting, I've discovered that's what printed has something to do with what's visible in the viewport.  The object I'm trying to print is in a scrollable viewport, and what prints is close to the same height as what's visible in the viewport.  If I resize the window to make the visibile area smaller, the amount of text that prints gets smaller.  However, what prints is not exactly what is in the viewport--I'm sure it's related somehow, since the amount of visible text (measured vertically) is consistently related to the viewport size.  But it isn't exactly the same.  Sometimes there is something visible in the viewport on screen that doesn't appear in the printed output, and vice versa.  But what prints changes when you scroll the viewport up and down.

       

      Any suggestions?  How can I get it to print the entire itemsToPrintContainer object, with all text, regardless of what's currently visible on the screen?

        • 1. Re: FlexPrintJob produces print output missing large blocks of text
          Flex harUI Adobe Employee

          That's a known bug.  If you can take the container outside of all scrollers

          then it should print.

          • 2. Re: FlexPrintJob produces print output missing large blocks of text
            JoshBeall Community Member

            I can't, it needs to be in a scroller.  Is there any other workaround?

             

            I thought of trying to take a snapshot with mx.graphics.ImageSnapshot, but once I've got the BitmapData, I don't know how to send it to the printer.  The FlexPrintJob.addObject method wants a UIComponent, not BitmapData.  So, I created an mx.controls.Image object, and set its source to the BitmapData, and passed that to FlexPrintJob.addObject, and it threw a null reference exception because Image.systemManager was unset.  So I set image.systemManager to be the same as itemsToPrintContainer.systemManager, and now no null reference exception--but nothings prints.

            • 3. Re: FlexPrintJob produces print output missing large blocks of text
              Subeesh Arakkan Community Member

              Hi,

               

              I faced similar issues while trying to print a VGroup inside a scroller and had to use MX controls to get the page printed correctly. This is against the rules (?) but works for me

               

               

              from

               

              <s:Scroller width="100%" height="100%">
                        <s:VGroup id="container" width="100%"/>
                   </s:Scroller>

               

               

              to
                   
                   <mx:Canvas width="100%" height="100%">
                        <mx:VBox id="container" width="100%"/>
                   </mx:Canvaswidth>

              • 4. Re: FlexPrintJob produces print output missing large blocks of text
                Flex harUI Adobe Employee

                Why would it need to be in a scroller at the time you submit the print job?

                Flash is a deferred renderer.  You can manipulate the display list, submit

                the page and restore the display list and the user will not see it.

                 

                Or clone the page somewhere, print it, and remove the clone.

                • 5. Re: FlexPrintJob produces print output missing large blocks of text
                  JoshBeall Community Member

                  Flex harUI wrote:

                   

                  Why would it need to be in a scroller at the time you submit the print job?

                  Flash is a deferred renderer.  You can manipulate the display list, submit

                  the page and restore the display list and the user will not see it.

                   

                  Or clone the page somewhere, print it, and remove the clone.

                   

                  I didn't realize that would work.  Here's what I wound up doing, and this seems to be working (with a few issues--see below):

                   

                   

                  var printer:FlexPrintJob = new FlexPrintJob();
                  
                  // Display the print dialog to the user.  If they choose a printer
                  // and click "print", this method will return true, and we will
                  // spool the job to the printer they selected. If they hit cancel,
                  // this method will return false, and we will not attempt to send
                  // anything to the printer.
                  if(printer.start()){
                       // Add some padding before spooling the object to the printer.
                       // This will give it a reasonable margin on the printout.
                       itemsToPrintContainer.paddingBottom = 100;
                       itemsToPrintContainer.paddingTop = 100;
                       itemsToPrintContainer.paddingLeft = 100;
                       itemsToPrintContainer.paddingRight = 100;
                       
                       
                       this.removeElement(itemsToPrintContainer);
                       FlexGlobals.topLevelApplication.addElement(itemsToPrintContainer);
                       printer.addObject(itemsToPrintContainer);
                       printer.send();
                       FlexGlobals.topLevelApplication.removeElement(itemsToPrintContainer);
                       this.addElement(itemsToPrintContainer);
                       
                       // Reset the margins to 0 for display on the screen.
                       itemsToPrintContainer.paddingBottom = 0;
                       itemsToPrintContainer.paddingTop = 0;
                       itemsToPrintContainer.paddingLeft = 0;
                       itemsToPrintContainer.paddingRight = 0; 
                  }
                  

                   

                   

                  The first issue is minor: the display will briefly display the "alternate" version of the itemsToPrintContainer, when it is moved to be a child element of the application object, and it's margins are adjusted.  This, I'll just live with.  I don't think anybody's going to get too upset about that.

                   

                  The second issue is more significant, but is not related to the workaround.  I think it's a more general printing and pagination issue.  There is no bottom margin on the first page if there are multiple pages, and there are no top or bottom margins on any subsequent pages, except the last page, which has only a bottom margin.  This makes sense, if you think about how I added a "margin".  I took the object, and added padding on all sides.  That works fine if you're only printing one page. But if you have to chop that object up to span multiple pages, then you can visual how the "middle" pages would not have a top or bottom "margin" (i.e., padding), since the margin/padding only exists at the outside edges of the object, not at spots where it was chopped up to fit onto separate pages.

                   

                  So, that leads me to my next question... how can I set margins on my printed output?  I asked about that here, and included my idea of adding padding--but I didn't know at the time it would not work for top and bottom margins if your content exceeded one page.

                   

                    -Josh

                  • 6. Re: FlexPrintJob produces print output missing large blocks of text
                    JoshBeall Community Member

                    Is there a bug for this logged at bugs.adobe.com?  I've been searching and haven't been able to find it.  I'd like to vote for it and watch it so I'll be aware when it's resolved.

                     

                      -Josh

                    • 7. Re: FlexPrintJob produces print output missing large blocks of text
                      Flex harUI Adobe Employee

                      I only know of an internal bug. It is assigned for fixing right now.  If I

                      find time, I'll create a public bug for it.

                      • 8. Re: FlexPrintJob produces print output missing large blocks of text
                        Flex harUI Adobe Employee

                        The player engineer says that it is related to this bug:

                        http://bugs.adobe.com/jira/browse/FP-6167