Tuesday, 29 March 2011

flex, how to print from flash / flex application...

problem:
Print is important from some applications, for any kind of receipt. Imagine that you may use resources from internet server to issue a doc at client's terminal where has nothing except a printer... i.e. tickets!

solution:
Flex supports a very easy way to print... just create a Group container (or a display container in general) and pass in addPage method...
The follow example prints itself (as I pass the this as argument to addPage method).

            internal function print():void{
                var printJob:PrintJob = new PrintJob();
                if (printJob.start()){      //this open's the dialog
                    printJob.start();       //if user choose 'print' then... start
                    printJob.addPage(this);
                    printJob.send();
                }
            }


Read the help about the PrintJob object where is not complex and it is tiny.

disadvantages:
The user has to press the print button in the system's print dialog box.
You cannot adjust the page size.

No comments:

Post a Comment