Programmatically print SWF

I was looking for a way to programmatically print a SWF file. The stand-alone Flash player has an option to print a SWF, however there is no shell action registered for it.

After looking around a bit, I found that probably the easiest way is to use the ActionScript PrintJob API:

package
{
	import flash.display.Loader;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.net.URLRequest;
	import flash.printing.PrintJob;
	
	public class Printer extends Sprite
	{
		private var loader:Loader;
		
		public function Printer()
		{
			loader = new Loader();
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaded);
			loader.load(new URLRequest("content.swf"));
		}
		
		public function onLoaded(e:Event):void
		{
			var pj:PrintJob = new PrintJob();
			if(pj.start()) {
				var sprite:Sprite = new Sprite();
				sprite.addChild(loader);
				pj.addPage(sprite);
				pj.send();
			}
		}
	}
}

3 thoughts on “Programmatically print SWF

  1. mani

    Thank u very much. I have a problem. when my swf included multi-page ,, these code print just the first page of the swf. what should I do?

    Reply
  2. mani

    there is no problem with loading, by these code I could see all the content of my external swf
    loader = new Loader();

    loader.load(new URLRequest(“content.swf”));

    but by the codes for printing the content of swf, just the first page of my swf would be printed.I guess I should apply several sprite or some things like that, but I dont know how?of course I applied these codes:
    pj.firstPage=1
    pj.lastPage=2;
    but didnt work………

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *