인쇄 예제: 배율 조절, 자르기 및 자동 맞춤

Flash Player 9 이상, Adobe AIR 1.0 이상

화면에 나타나는 방식과 용지에 인쇄되어 나타나는 방식의 차이에 따라 인쇄할 때 표시 객체의 크기나 다른 속성을 조정해야 하는 경우가 있습니다. scaleX scaleY 속성을 사용하는 등 인쇄하기 전에 표시 객체의 속성을 조절할 때 객체 크기가 인쇄 영역에 정의된 사각형보다 크면 객체가 잘립니다. 페이지를 인쇄한 후에는 속성을 원래대로 설정할 수도 있습니다.

다음 코드에서는 txt 표시 객체(녹색 상자 배경 제외)의 크기를 조절하고 지정된 사각형의 크기에 따라 텍스트 필드가 잘립니다. 인쇄한 후에는 텍스트 필드가 화면상에 표시되는 원래 크기로 돌아갑니다. 사용자가 운영 체제의 [인쇄] 대화 상자에서 인쇄 작업을 취소하면 Flash 런타임의 내용이 변경되어 작업을 취소한 사용자에게 경고를 표시합니다.

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; 
        } 
    } 
}