Flex 3.2:FlexPrintJob每页输出一行PrintDataGrid

时间:2012-05-13 03:27:08

标签: actionscript-3 flex printing datagrid flex3

我正在尝试使用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>

打印输出看起来像这样 One Row Per Page

1 个答案:

答案 0 :(得分:0)

通过向TitledWindow对象(PrintDataGrid的包装器)添加'height'参数来解决该问题。当高度设置为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>