zoukankan      html  css  js  c++  java
  • Using Flex Buildin Print Function(Flex 打印功能系列转载)

    The build-in print function provided by Adobe Flex is actually pretty straightforward. For a single page print, it is good enough. Here is how it works:

    Things You Need

    • mx.printing.FlexPrintJob

    Steps You Do

    1. Create a FlexPrintJob Instance     
       var flexPrintJob: FlexPrintJob = new FlexPrintJob();
    
    2. Start FlexPrintJob
       flexPrintJob.start();
    
    3. Add Target Component to FlexPrintJob 
       printJob.addObject(targetComponent);
    
    4. Print
       printJob.send();

    Sample Code

    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="absolute"
        initialize="init()">
    
        <mx:Script>
        	<![CDATA[
        	import mx.printing.FlexPrintJob;
        	import mx.collections.ArrayCollection;
    
        	[Bindable]
        	public var dataSource:ArrayCollection = new ArrayCollection();
    
            private var totalRecords:Number = 15; 
    
        	private function init():void {
    		for (var i:int = 1; i<=totalRecords; i++) {
        		     var dataObject:Object = new Object();
        		     dataObject.Name = "Name #" + i;
        		     dataObject.Phone = "Phone #" + i;
        		     dataObject.Address = "Address #" + i;
        		     dataSource.addItem(dataObject);
        		}
        	}
    
        	private function doPrint():void {
        		var printJob:FlexPrintJob = new FlexPrintJob();
        	   	if (printJob.start()) {
        	            printJob.addObject(myData);
        		    printJob.send();
        		}
        	}
    
        	]]>
        </mx:Script>
    
        <mx:Panel title="Flex Tutorial - Print"
        	width="500" height="500"
        	horizontalCenter="0" verticalCenter="0"
        	horizontalAlign="center" verticalAlign="middle">
    
            <mx:DataGrid id="myData"
                dataProvider="{dataSource}"
                width="400" height="400" />
    
            <mx:Button label="Print" click="doPrint()"/>
    
        </mx:Panel>
    
    </mx:Application>
    

    Conclusion

    Adobe Flex provides FlexPrintJob to handle the print request. It is very simple to use. However, the biggest challenge is printing multiple pages. In the above sample code, if you change the code,

    From:

    private var totalRecords:Number = 15;
    

    To:

    private var totalRecords:Number = 100;
    

    It will generate 100 records in the DataGrid. Guess how many of them will be printed if you click the Print button?  Depends on your page and printer setting, maybe just 17-20. You will even see a ugly vertical scoll bar. The problem here is, FlexPrintJob itself can not SCOLL those Scollable Components like DataGrid or TextArea.

    To resolve this problem, Adobe provides a workaround in Flex framework. In the next tutorial, we will see Printing Multiple Pages Using PrintDataGrid.

    source:http://flextutorial.org/2009/05/21/using-flex-build-in-print-function/

  • 相关阅读:
    Bzoj1027 [JSOI2007]合金
    Bzoj4318 OSU!
    Bzoj3931 [CQOI2015]网络吞吐量
    Bzoj3551 [ONTAK2010]Peaks加强版
    Bzoj3545 [ONTAK2010]Peaks
    Bzoj4031 [HEOI2015]小Z的房间
    Bzoj3613 [Heoi2014]南园满地堆轻絮
    Bzoj4516 [Sdoi2016]生成魔咒
    HDU1847 Good Luck in CET-4 Everybody!
    HDU1846 Brave Game
  • 原文地址:https://www.cnblogs.com/wuhenke/p/1608209.html
Copyright © 2011-2022 走看看