Tuesday, January 25, 2011

How to print a MovieClip/Sprite/Image:

Below is the code to send a MovieClip/Sprite/Image to the printer.  The minimum requirement is Flash Player 9 or Air 1.0.
 




import flash.printing.PrintJob;

/**
 * This function will print a sprite.
 *
 * @param  image  the sprite to be printed or send to printer
 */
function printImage( image:Sprite ) : void {
    var pj:PrintJob = new PrintJob();
    var pagesToPrint:uint = 0;
   
    if( pj.start() ) {               
       
        image.height = pj.pageHeight;
        image.width  = pj.pageWidth;
   
        try {
            pj.addPage(image);
            pagesToPrint++;
        }
        catch(e:Error) {
            // do nothing
        }
   
        if(pagesToPrint > 0) {
            pj.send();
        }
    }
}

Related Links:

  

6 comments:

  1. it can't be that easy...

    ReplyDelete
  2. well, you have to add a button that will perform the function. Anyone tried?

    ReplyDelete








  3. global
    {
    color: #FFFFFF;
    }

    .dataTip
    {
    color: #000000;
    }






    ReplyDelete








  4. global
    {
    color: #FFFFFF;
    }

    .dataTip
    {
    color: #000000;
    }






    ReplyDelete
  5. Replies








    1. global
      {
      color: #FFFFFF;
      }

      .dataTip
      {
      color: #000000;
      }






      Delete