如何在打印Print AdvancedDataGrid时创建上边距

时间:2013-10-02 04:26:06

标签: flex printing datagrid

我的数据网格从页面的最顶部开始打印。我无法弄清楚如何将数据网格向下移动。我没有在FlexPrintJob或PrintAdvancedDataGrid中看到任何可以执行此操作的内容。我是否必须创建一个空白对象才能添加到FlexPrintJob对象的顶部?

任何有用的帮助或链接。

谢谢,

约翰

1 个答案:

答案 0 :(得分:0)

在尝试了很多adobe和其他根本不适用于我的例子后,我发现我必须将数据网格放在一个vBox中,我可以在数据网格上方放置一个空白标题。正如所有示例所示,最好使用vBox组件。

以下是我提出的一个工作示例,与我找到的示例略有不同。在vBox组件中,您可以做很多事情来增强打印作业。在我的情况下,我添加了标题和日期。

希望这可以帮助那些人,

约翰


我正在使用通用函数来打印我的应用程序中可能存在的任何AdvancedDataGrid ...

public function printAdvancedDataGridContents(advDG:AdvancedDataGrid, xmlListCollection:XMLListCollection, headerText:String):void
    {
        const printJob:FlexPrintJob = new FlexPrintJob();               
        if ( printJob.start() ) {
            //create an instance of the FormPrintView_ADG component containing the datagrid
            var thePrintView:FormPrintView_ADG = new FormPrintView_ADG();
            //add the component to my application
            FlexGlobals.topLevelApplication.addChild(thePrintView);
            //load the datagrid
            thePrintView.printDataGrid.dataProvider = xmlListCollection.copy();
            //format the datagrid
            thePrintView.printDataGrid.width = printJob.pageWidth-45; //set a left margin for the dg in a right justiified vBox
            thePrintView.printDataGrid.height = printJob.pageHeight-73; //page adjusted for header title and date
            thePrintView.printDataGrid.setStyle("fontSize", 8);
            thePrintView.printDataGrid.columns = advDG.columns;
            thePrintView.printDataGrid.setStyle("fontFamily", 'Times');
            thePrintView.printDataGrid.setStyle("color", 000000);
            //set the header text
            thePrintView.headerText.height = 45;
            thePrintView.headerText.width = printJob.pageWidth-20;
            thePrintView.headerText.text = "\r"+headerText;
            //add the first page to the print job
            printJob.addObject(thePrintView, FlexPrintJobScaleType.NONE);
            while (thePrintView.printDataGrid.validNextPage) {
                // Move the next page of data to the top of the PrintDataGrid and add it to the printjob
                thePrintView.printDataGrid.nextPage();
                printJob.addObject(thePrintView, FlexPrintJobScaleType.NONE);                       
            }
            //print it and remove the component from my application
            printJob.send();
            FlexGlobals.topLevelApplication.removeChild(thePrintView);                  
        }
    }

这是我正在使用的vBox组件......

<?xml version="1.0"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml"
    horizontalAlign="right"
    creationComplete="init();">

    <mx:Script>
    <![CDATA[
        [Bindable] private var date:String;

        private function init():void{
            date = new Date().toString();
            date = df.format(date);
        }
    ]]>
    </mx:Script>

    <mx:DateFormatter id="df" formatString="EEEE, MMMM D, YYYY"/>
    <!-- this header can contain a title or be left blank to create a top margin -->
    <mx:TextArea id="headerText"  borderThickness="0" color="#000000" fontWeight="bold"
                textAlign="center" textDecoration="none"/>
    <!-- date label. set visible to false in the calling function if not needed -->
    <mx:Label color="#000000" fontSize="8" fontStyle="normal" fontWeight="normal" text="{date}"/>
    <!-- the data grid -->
    <mx:PrintAdvancedDataGrid id="printDataGrid"/>  
</mx:VBox>