Adobe Flex 3 ヘルプ

例:拡大 / 縮小、トリミング、および応答

場合によっては、画面の表示とプリントとの外観上の違いに対応するために、表示オブジェクトのサイズ (またはその他のプロパティ) をプリント時に調整する必要が生じることがあります。プリントの前に表示オブジェクトのプロパティ(例:scaleX および scaleY プロパティ)を調整する際には、プリント範囲を定義する矩形よりも大きくオブジェクトを拡大するとトリミングが発生することに注意してください。また、多くの場合には、ページをプリントした後でプロパティを元の値に戻す必要があります。

次のコードでは、txt 表示オブジェクトの寸法を拡大(ただし、背景にある緑色のボックスはそのまま)した結果、指定した矩形のサイズでテキストフィールドがトリミングされます。プリントした後は、テキストフィールドを画面表示用の元のサイズに戻します。ユーザーが OS の印刷ダイアログボックスでプリントジョブをキャンセルした場合は、Flash Player または AIR の表示内容を変更し、ジョブがキャンセルされたことを警告します。

package
{
    import flash.printing.PrintJob;
    import flash.display.Sprite;
    import flash.text.TextField;
    import flash.display.Stage;
    import flash.geom.Rectangle;
     
    public class PrintScaleExample extends Sprite
    {
        private var bg:Sprite;
        private var txt:TextField;

        public function PrintScaleExample():void
        {
            init();
            draw();
            printPage();
        }
        
        private function printPage():void
        {
            var pj:PrintJob = new PrintJob();
            txt.scaleX = 3;
            txt.scaleY = 2;
            if (pj.start())
            {
                trace(">> pj.orientation: " + pj.orientation);
                trace(">> pj.pageWidth: " + pj.pageWidth);
                trace(">> pj.pageHeight: " + pj.pageHeight);
                trace(">> pj.paperWidth: " + pj.paperWidth);
                trace(">> pj.paperHeight: " + pj.paperHeight);    

                try
                {
                    pj.addPage(this, new Rectangle(0, 0, 100, 100));
                }
                catch (error:Error)
                {
                    // Do nothing.
                }
                pj.send();
            }
            else
            {
                txt.text = "Print job canceled";
            }
            // Reset the txt scale properties.
            txt.scaleX = 1;
            txt.scaleY = 1;
        }
        
        private function init():void
        {
            bg = new Sprite();
            bg.graphics.beginFill(0x00FF00);
            bg.graphics.drawRect(0, 0, 100, 200);
            bg.graphics.endFill();
            
            txt = new TextField();
            txt.border = true;
            txt.text = "Hello World";
        }
        
        private function draw():void
        {
            addChild(bg);
            addChild(txt);
            txt.x = 50;
            txt.y = 50;
        }
    }
}

 

このページに新しいコメントが追加された場合に、電子メールでの通知を希望する。 | コメントレポート