# Print an image from flash?

**URL:** <https://forum.kirupa.com/t/print-an-image-from-flash/292924>\
**Category:** Uncategorized\
**Created:** [July 20, 2009, 11:46pm UTC](https://forum.kirupa.com/t/print-an-image-from-flash/292924 "2009-07-20T23:46:59Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![theycallmegosu](https://avatars.discourse-cdn.com/v4/letter/t/d2c977/32.png) [@theycallmegosu](https://forum.kirupa.com/u/theycallmegosu)\
**Post date:** [July 20, 2009, 11:46pm UTC](https://forum.kirupa.com/t/print-an-image-from-flash/292924/1 "2009-07-20T23:46:59Z")

</div>

is there a way to print an image from flash?? it is better to have an example with text printing because i need to print both things at a time. here is my code, it is somehow not working.

package {  
import flash.display.Sprite;  
import flash.display.Loader;  
import flash.display.Bitmap;  
import flash.display.BitmapData;  
import flash.printing.PrintJob;  
import flash.printing.PrintJobOptions;  
import flash.events.Event;  
import flash.events.IOErrorEvent;  
import flash.net.URLRequest;  
import flash.geom.Matrix;  
public class printAsBitmapExample extends Sprite {  
private var frame:Sprite = new Sprite();  
private var [url:String](http://www.kirupa.com/forum/String) = “homeImage/image.jpg”;  
private var loader:Loader = new Loader();  
public function printAsBitmapExample() {  
var request:URLRequest = new URLRequest(url);

```
       loader.load(request);
       loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
       loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
    }
    private function completeHandler(event:Event):void {
    
        var picture:Bitmap = Bitmap(loader.content);
        var bitmap:BitmapData = picture.bitmapData;
       var myBitmap:BitmapData = new BitmapData(loader.width, loader.height, false);
        var matrix:Matrix = new Matrix();

```

trace((200 / bitmap.width)+", "+(200 / bitmap.height));  
matrix.scale((200 / bitmap.width), (200 / bitmap.height));

```
        frame.graphics.lineStyle(10);
        frame.graphics.beginBitmapFill(bitmap, matrix, true);
        frame.graphics.drawRect(0, 0, 200, 200);
        frame.graphics.endFill();
        addChild(frame);
         
        printPage();    
    }
    private function ioErrorHandler(event:IOErrorEvent):void {
        trace("Unable to load the image: " + url);
    }
    private function printPage ():void {
        var myPrintJob:PrintJob = new PrintJob();
        var options:PrintJobOptions = new PrintJobOptions();
        options.printAsBitmap = true;
        
        myPrintJob.start();

        try {
            myPrintJob.addPage(frame, null, options);
        }
        catch(e:Error) {
            trace ("Had problem adding the page to print job: " + e);
        }

        try {
trace(frame.width+"/"+frame.height);
         myPrintJob.send();
        }
        catch (e:Error) {
            trace ("Had problem printing: " + e);    
        }
    }
}

```

}

i can trace the frame width and height. but no image printed.
