Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>After trying a lot of examples form adobe and others that did not work at all for me, I figured out that I had to put the datagrid in a vBox where I could put a blank header above the datagrid. As all of the examples showed, this was best done with a vBox component. </p> <p>Below is a working example of what I came up with, which is a bit different than the examples I found. In the vBox component you can do a lot of things to enhance the print job. In my case I added a title and date. </p> <p>Hope this helps someone out there,</p> <p>John</p> <hr> <p>I am tusing a generic function to print any AdvancedDataGrid I might have in my application...</p> <pre><code>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); } } </code></pre> <hr> <p>Here is the vBox component I am using...</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" horizontalAlign="right" creationComplete="init();"&gt; &lt;mx:Script&gt; &lt;![CDATA[ [Bindable] private var date:String; private function init():void{ date = new Date().toString(); date = df.format(date); } ]]&gt; &lt;/mx:Script&gt; &lt;mx:DateFormatter id="df" formatString="EEEE, MMMM D, YYYY"/&gt; &lt;!-- this header can contain a title or be left blank to create a top margin --&gt; &lt;mx:TextArea id="headerText" borderThickness="0" color="#000000" fontWeight="bold" textAlign="center" textDecoration="none"/&gt; &lt;!-- date label. set visible to false in the calling function if not needed --&gt; &lt;mx:Label color="#000000" fontSize="8" fontStyle="normal" fontWeight="normal" text="{date}"/&gt; &lt;!-- the data grid --&gt; &lt;mx:PrintAdvancedDataGrid id="printDataGrid"/&gt; &lt;/mx:VBox&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload