Vladimir Panteleev
Vladimir Panteleev

Reputation: 25187

Print SWF programmatically

The stand-alone Flash player has an option to print a SWF. However, there is no shell action registered for this, and as far as I can see the only way to do it is to use a keyboard macro (or do something invasive such as inject a DLL in the player). Is there some official API for this?

Upvotes: 0

Views: 1111

Answers (1)

Vladimir Panteleev
Vladimir Panteleev

Reputation: 25187

Found it! 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();
            }
        }
    }
}

Upvotes: 1

Related Questions