【问题标题】:Flex 3.2: FlexPrintJob outputs PrintDataGrid one row per pageFlex 3.2:FlexPrintJob 每页输出一行 PrintDataGrid
【发布时间】:2012-05-21 02:20:54
【问题描述】:

我正在尝试使用 FlexPrintJob 在 Flex 3.2 中打印表格。我需要正常的打印行为 - 如果所有行都适合单页,则需要一页,如果有足够的数据可以填充多页,则需要整页的行,然后是部分填充的页面。不知何故,我得到了每行一页,其中每一页都有一个表头,然后是一行数据,然后是空格。

包含 15 行的表格会生成 15 页的文档。我在 Firefox 和 IE8 中得到相同的行为。

是什么导致了这种行为? 感谢您的帮助!

代码如下:

        // The function to print the output.
    public function onPrint():void {
        var printJob:FlexPrintJob = new FlexPrintJob();
        printJob.start();

        var thePrintView:FormPrintView = new FormPrintView();
        addChild(thePrintView);
        thePrintView.initPrintDataGrid(openSequences);
        // thePrintView.printOpenTimeGrid.dataProvider = printOpenTime.dataProvider;
        thePrintView.validateNow();

        thePrintView.width=printJob.pageWidth;
        thePrintView.height=printJob.pageHeight;

        printJob.addObject(thePrintView, FlexPrintJobScaleType.MATCH_WIDTH);

        while (thePrintView.printOpenTimeGrid.validNextPage) {
            //Put the next page of data in the view.
            thePrintView.printOpenTimeGrid.nextPage();
            //Queue the additional page.
            printJob.addObject(thePrintView, FlexPrintJobScaleType.MATCH_WIDTH);
        }

        printJob.send();
        removeChild(thePrintView);
        this.onClose();
    }

PrintDataGrid 直接位于 TitleWindow 对象中:

   <!-- The data grid. The sizeToPage property is true by default, so the last
    page has only as many grid rows as are needed for the data. -->
<mx:PrintDataGrid id="printOpenTimeGrid" dataProvider="{openSequences}" sizeToPage="true" width="100%" height="100%">
    <mx:columns>
        <mx:DataGridColumn dataField="startDate" headerText="Seq Date" width="70">
            <mx:itemRenderer>
                <mx:Component>
                    <mx:VBox>
                        <mx:DateFormatter id="startDateFormatter" formatString="M/D/YYY"/>
                        <mx:Label fontWeight="bold" text="{startDateFormatter.format(data.startDate)}"/>
                    </mx:VBox>
                </mx:Component>
            </mx:itemRenderer>
        </mx:DataGridColumn>
        <mx:DataGridColumn dataField="equipCode" headerText="EQP" width="40" />
        <mx:DataGridColumn dataField="base" headerText="BSE" width="40" />
        <mx:DataGridColumn dataField="sequenceNumber" headerText="SEQNO" width="45" />
        <mx:DataGridColumn dataField="seat" headerText="ST" width="40" />
        <mx:DataGridColumn headerText="DPRT" width="40">
            <mx:itemRenderer>
                <mx:Component>
                    <mx:VBox>
                        <mx:DateFormatter id="departTimeFormatter" formatString="JJNN"/>
                        <mx:Label fontWeight="bold" text="{departTimeFormatter.format(data.startDate)}"/>
                    </mx:VBox>
                </mx:Component>
            </mx:itemRenderer>
        </mx:DataGridColumn>
        <mx:DataGridColumn dataField="terminationDate" headerText="ARVL/DT" width="60" >
            <mx:itemRenderer>
                <mx:Component>
                    <mx:VBox>
                        <mx:DateFormatter id="arvDateFormatter" formatString="JJNN/DD"/>
                        <mx:Label fontWeight="bold" text="{arvDateFormatter.format(data.startDate)}"/>
                    </mx:VBox>
                </mx:Component>
            </mx:itemRenderer>
        </mx:DataGridColumn>
        <mx:DataGridColumn dataField="tripValue" headerText="TTL" width="50" />
        <mx:DataGridColumn dataField="blockType" headerText="Block Type" width="170" />
    </mx:columns>
</mx:PrintDataGrid>

打印输出如下

【问题讨论】:

    标签: actionscript-3 apache-flex printing datagrid flex3


    【解决方案1】:

    通过将“height”参数添加到 TitledWindow 对象(PrintDataGrid 的包装器)来解决问题。当高度设置为 800 时,内容会打印到整页上,并且不显示滚动条。

    <mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml" title="Open Time" height="800">
    <mx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;
            import mx.core.*;
    
            [Bindable]
            private var openSequences:ArrayCollection;
    
            public function initPrintDataGrid(sequences:ArrayCollection):void {
                openSequences = sequences;
            }
        ]]>
    </mx:Script>
    
    <!-- The data grid. The sizeToPage property is true by default, so the last
        page has only as many grid rows as are needed for the data. -->
    <mx:PrintDataGrid id="printOpenTimeGrid" dataProvider="{openSequences}" sizeToPage="true" 
        width="100%" height="100%">
        <mx:columns>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-20
      • 2020-06-09
      • 1970-01-01
      • 1970-01-01
      • 2018-01-07
      相关资源
      最近更新 更多