This casestudy demonstrates how to use PrintAdvancedDataGrid and a custom itemRenderer to print multiple pages of data and graphics, using the SWFloader component.
Final Result Preview
Let’s take a look at the final result we will be working towards – below is an overview of a 12 page PDF printed from a Flex application using the techniques in this article:
Demonstrated in This Tutorial:
- Using FlexPrintJob class.
- Using
PrintAdvancedDataGrid. - Creating a custom
itemRendererwith aSWFLoader. - Printing a header and footer.
- Filtering a
collectionView. - Printing a
DataGridwith height that exceeds 7500.
Some Difficulties With Regards to Flex Printing:
- Your content or
DataGridrows must all be visible on the stage or they won’t print. - Adding manual page breaks is difficult, and achieved through setting your
rowHeightto match what you want displayed on each printed page. - Flex printing goes haywire if your total
PrintAdvancedDataGridcontent height is greater than approximately 7500 pixels, necesitating a workaround of multiplePrintAdvancedDataGrids.
Step 1: Import the Printing Classes
Begin by importing the necessary print classes, as well as your print renderer into your Flex project:
import mx.printing.FlexPrintJob; import mx.printing.FlexPrintJobScaleType; import com.reiman.PrintItemRenderer;
Step 2: Create a View for PrintAdvancedDataGrid and itemRenderer
Create a view State for your bulk printing. In my case, I created a state called printState.
*alternatively, you can create an instance of your PrintAdvancedDataGrid and itemRenderer and add them to the stage via actionscript, but for a bulk printing project I found this to be too difficult to work with, and as I was trying to print SWFs that are XML driven, I needed to make sure that my SWFs were displaying correctly before printing.
Step 3: Add Your PrintAdvancedDataGrid
<mx:PrintAdvancedDataGrid
paddingTop="0"
paddingBottom="0"
visible="true"
rowHeight="200"
sizeToPage="true"
showHeaders="false"
id="printGrid"
creationComplete="stripQuiz();"
height="{grid_height}"
width="300">
<mx:columns>
<mx:AdvancedDataGridColumn
width="200"
id="printColumn"
itemRenderer="com.reiman.PrintItemRenderer"
sortable="false" />
</mx:columns>
</mx:PrintAdvancedDataGrid>
If you need a total printing area greater than 7500 in height, you’ll need another PrintAdvancedDataGrid for each area
Step 4: Set Your PrintAdvancedDataGrid options
One thing I found important was to set the option
sizetoPage="true"
According to the PrintDataGrid Control page from the Adobe Flex 3 LiveDocs, the sizeToPage property makes sure that the PrintAdvancedDataGrid control removes any partially visible or empty rows and to resize itself to include only complete rows in the current view.
Step 5: Add Your itemRenderer
Add an itemRenderer to your AdvancedDataGridColumn [...]
No comments:
Post a Comment