16 Replies Latest reply on Apr 6, 2011 11:37 AM by atariot

    image not displayed using FlexPrintJob

    Tejas S Patel

      Hello All,

      I am trying to get printout of customize data using actionscript.

      I am using FlexPrintJob class.

       

      I am facing problem in getting image on printout layout.

      I have attached full description and code here.

       

      Does anyone know why causes this, or what I could do to fix it?


      Thanks in advance for your help.

        • 1. Re: image not displayed using FlexPrintJob
          Flex harUI Adobe Employee

          I don't have time right now to look at your code, but you can't load

          external images after you start a print job.

          • 2. Re: image not displayed using FlexPrintJob
            Tejas S Patel Level 1

            Thank you Alex Harui.

            is there any other way to implement that my feature?

            and also is it possible, to get image in printout which is already loaded on Flex Image component.?

            • 3. Re: image not displayed using FlexPrintJob
              Tejas S Patel Level 1

              i have tried to export whole HBox object to print-out layout.

              printing layout getting very fine with HBox control (containing image).

              problem is when print-out layout completed, my HBox control will hide from my flex application.

              it happens very strange.

               

              ImagePrintView.mxml     custom component for print

              ImageHBox - HBox control of Flex application (having one image)

               

              code:

               

              private function doPrint() : void

              {

                 var printJob:FlexPrintJob = new FlexPrintJob();

                 if (printJob.start())

                 {

                    var obView:ImagePrintView = new ImagePrintView();

                    addChild(obView);

                    obView.width=printJob.pageWidth;

                    obView.height=printJob.pageHeight;

                    obView.ImageTitle.text = 'Image displayed of HBox Control';

                    obView.addChild(ImageHBox);

                    printJob.addObject(obView);

                 }

                removeChild(obView);

                printJob.send();

              }

               

               

              is there any wrong in code? OR any other idea?

              • 4. Re: image not displayed using FlexPrintJob
                MarketlinxDev

                Alex,

                 

                Could you tell me why it's not possible to load external images (or any resources for that matter) after you've started a print job? I'm working on a reporting system that generates reports on the fly via a type of template system and requests images, maps (UMap) and chart just before we add the page to the print job so we don't potentially have to generate (and request resources for) hundreds of pages in advance.

                 

                Thanks,

                 

                Mike

                • 5. Re: image not displayed using FlexPrintJob
                  Flex harUI Adobe Employee

                  External Images take a minimum of one extra frame to load and one a print

                  job starts, you cannot run any code to handle the loading of that image.

                   

                  That is due to be fixed in AIR 2.0 so you could consider creating an AIR

                  app.  No guarantees when that will be fixed in the browser plugins.

                  • 6. Re: image not displayed using FlexPrintJob
                    Flex harUI Adobe Employee

                    RemoveChild is removing something.   Is it going to remove the Hbox?

                    • 7. Re: image not displayed using FlexPrintJob
                      benjami3

                      So, what should we do if we are currently loading external images into our print job?  I have the same problem as Tejas S Patel and MarketlinxDev and I am going to ask the same question: Is there a way to load images before it gets to the print job then?  Since it takes one frame extra to load images, could I somehow load all of the images beforehand and then start the print job?

                       

                      Thanks

                       

                      Ben

                       


                      • 8. Re: image not displayed using FlexPrintJob
                        Tejas S Patel Level 1

                        i have just adding HBox to print job.

                         

                        obView.addChild(ImageHBox);

                         

                        when print job is completed, my HBox(ImageHBox) is hide from flex application.

                        I have never used RemoveChild.

                        • 9. Re: image not displayed using FlexPrintJob
                          Flex harUI Adobe Employee

                          There was a removeChild at the end of your code

                          • 10. Re: image not displayed using FlexPrintJob
                            Flex harUI Adobe Employee

                            I'd do a search and see what others have done.  Maybe you can put up another

                            dialog first to buy you time to preload the images.

                            • 11. Re: image not displayed using FlexPrintJob
                              Tejas S Patel Level 1

                              Ohhh. so because of that HBox is removed from flex application.

                              Thank you Alex.

                              Its my mistake and misunderstanding of print concept.

                              • 12. Re: image not displayed using FlexPrintJob
                                MarketlinxDev Level 1

                                Hey Ben,

                                 

                                What we did in the end was just load and render all our "pages" (which include all the external images) before we create and start the print job. This is not really how we wanted to do it but I suppose it's all the same. The one thing you have to remember is when you're loading anything external, you need to ensure that they are fully loaded before adding them to the print page. So if you have 5 images on a page and assign them a URL, you will need to synchronize all those images (Event.COMPLETE) before spooling them or you'll get blank images printed.

                                 

                                Actually what I ended up doing was creating a custom image object and using the SWFLoader to load the image, then assigned a FlexEvent.UPDATE_COMPLETE handler to the actual IMAGE object and finally assigning the SWFLoader's content to the source of the image and waiting for the FlexEvent.UPDATE_COMPLETE to finally fire from the image object so I was 100% sure the image data was loaded and fully rendered on the screen. I just couldn't depend on the IMAGE tag alone to fire the events in an order that I knew everything was ready and rendered (or likely I was doing something wrong).

                                 

                                Hopefully that helps a bit.

                                 

                                Alex: Thanks for your reply in regards to why you can't load an image after you've begun a printjob. It's a little disappointing to us only because we were hoping to gain a little performance with our reporting system utilizing databinding as to not create the same objects over and over again. AIR is not an option so hopefully the plugin receives an update in the future as well.

                                 

                                Mike

                                • 13. Re: image not displayed using FlexPrintJob
                                  benjami3 Level 1

                                  Thanks so much Mike, that was super helpful!

                                   

                                  Ben

                                  • 14. Re: image not displayed using FlexPrintJob
                                    MarketlinxDev Level 1

                                     

                                     

                                     

                                    No problem Ben...one other issue I ran into that will hopefully save you some time as well is once you have everything rendering out page after page, you'll need to ensure your "application" has it's "clipContent" property set to false or you'll have some of your page(s) printing but not others.

                                     

                                     

                                    I had a 7 page print out (fully rendered on the screen first of course) and the first page would print but only 1/4 of the second and then only the images and shading and borders (graphics library stuff) would print on the remaining even though I was adding the pages one at a time (the pages were Canvas objects) to the printjob. Tracked it down to the clipContent but I had to do it on the entire application (found some old 1.5 Flex documentation that it explained all of this oddly enough!). I still found it interesting that images and graphic drawn stuff would print, just not all the labels and text.

                                     

                                    Mike

                                    • 15. Re: image not displayed using FlexPrintJob
                                      paulcortez

                                      Hi Tejas,

                                       

                                      I recall from other thread that they suggest the use of Embed(source=""). I just passed by this thread because I also have the same issue with regards with printing. I'm using Flex4 right now but having a hardtime in creating my reports. At first, my PrintDataGrid prints a thick line underneath the header when printAsBitmap was set to false. I can't remove it so what I did, I created 1 PrintDataGrid on top of the other PrintDataGrid and set both showHeader to false. The 1st PrintDataGrid on top serves as the header and 2nd are the data. It show plain grids just the way I wanted to but only show half of the page. The rest are on the second page. Now back to zero. I removed the 1st PrintDataGrid. I set the showHeader to false on the remaining PrintDataGrid (which my data were shown) and add the column names as first row data. Now it works fine because no thick line underneath but on the 2nd page, there is no column header. When I was working with Flex3, I have no problem with report since I was using Flexreport (http://www.kemelyon.com/flexreport/0_2rc1/). After migrating to Flash Builder, I can no longer use Flexreport. One thing I also like to print in my report is images arranged in thumbnails but I have limited timeframe now. I changed to .Net (c#) but if there is a chance I could find an easy way to create report template in different layout, I'll switch to Flex. I find it easy to deploy and maintain. Also easy to do animations which is pleasing to look at.

                                      • 16. Re: image not displayed using FlexPrintJob
                                        atariot

                                        hello,

                                         

                                        In sample of  http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/printing/FlexPrintJo b.html


                                        Found the solution for print image :

                                        By loading the image class:

                                         

                                        [Embed(source="yourImage.jpg")]

                                        [Bindable]  public var myImageClass:Class;

                                         

                                        After call this class in your print script :

                                        thePrintView.header.img.source= myImageClass;

                                         

                                        I hope this will help.

                                        Anthony

                                        1 person found this helpful