Here's a short example of PrintJob copied from Components Explorer.
// The function to print the output.
public function doPrint():void {
var printJob:FlexPrintJob = new FlexPrintJob();
if (printJob.start()) {
// Create a FormPrintView control as a child of the current
view.
var thePrintView:FormPrintView = new FormPrintView();
Application.application.addChild (thePrintView);
//Set the print view properties.
thePrintView.width=printJob.pageWidth;
thePrintView.height=printJob.pageHeight;
thePrintView.prodTotal = prodTotal;
// Set the data provider of the FormPrintView component's
data grid
// to be the data provider of the displayed data grid.
thePrintView.myDataGrid.dataProvider =
myDataGrid.dataProvider;
// Create a single-page image.
thePrintView.showPage("single");
// If the print image's data grid can hold all the
provider's rows,
// add the page to the print job.
if(!thePrintView.myDataGrid.validNextPage)
{
printJob.addObject(thePrintView);
}
// Otherwise, the job requires multiple pages.
else
{
// Create the first page and add it to the print job.
thePrintView.showPage("first");
printJob.addObject (thePrintView);
thePrintView.pageNumber++;
// Loop through the following code until all pages are
queued.
while(true)
{
// Move the next page of data to the top of the
print grid.
thePrintView.myDataGrid.nextPage();
thePrintView.showPage("last");
// If the page holds the remaining data, or if the
last page
// was completely filled by the last grid data,
queue it for printing.
// Test if there is data for another PrintDataGrid
page.
if(!thePrintView.myDataGrid.validNextPage)
{
// This is the last page; queue it and exit the
print loop.
printJob.addObject(thePrintView);
break;
}
else
// This is not the last page. Queue a middle page.
{
thePrintView.showPage ("middle");
printJob.addObject(thePrintView);
thePrintView.pageNumber++;
}
}
}
// All pages are queued; remove the FormPrintView control to
free memory.
Application.application.removeChild(thePrintView);
}
// Send the job to the printer.
printJob.send();
}
Best
On 2/14/07, Ian Shafer <[EMAIL PROTECTED]> wrote:
Hello,
I'm using PrintDataGrid to print a DataGrid and everything is working
fine except one thing. The size (height) of the PrintDataGrid same one
every page. This would be okay if I were just printing the
PrintDataGrid, but I have a header on the first page (and footers on
subsequent pages).
The example code for this (in the "Developing Flex Applications" guide)
is great and I followed it to a tee (I think). My current solution is to
manually set the height of the PrintDataGrid after the first page. This
is a lame solution because I'm doing something like this:
printView.reportsTable.height = printJob.pageHeight - 20;
(If I set the height to printJob.pageHeight I get a scrollbar and my
footer (with page number) doesn't show.)
Any idea what's causing this?
Here's the pertinent code snippets:
** Application View **
private function printTable():void {
var printJob:FlexPrintJob = new FlexPrintJob();
if (!printJob.start()) { return; }
var printView:CategoryOrderReportTablePrintView = new
CategoryOrderReportTablePrintView();
var pageNumber:int = 1;
addChild(printView);
printView.width = printJob.pageWidth;
printView.height = printJob.pageHeight;
printView.reports = _reports;
printView.pageNumber = pageNumber;
printView.totals = this.calcTotals(this._reports);
printView.description = this.formatDate(_options.startDate) + " - "
+ this.formatDate(_options.endDate);
printJob.addObject(printView);
while (printView.reportsTable.validNextPage) {
pageNumber++;
printView.reportsTable.nextPage();
printView.reportsTable.height = printJob.pageHeight - 20;
printView.pageNumber = pageNumber;
printJob.addObject(printView)
}
printJob.send();
removeChild(printView);
}
** Print View **
public function set pageNumber(pageNumber:int):void {
footer.pageNumber = pageNumber;
if (pageNumber == 1) {
header.includeInLayout = true;
header.visible = true;
footer.includeInLayout = false;
footer.visible = false;
} else {
header.includeInLayout = false;
header.visible = false;
footer.includeInLayout = true;
footer.visible = true;
}
validateNow();
}
--
----------------------------
Igor Costa
www.igorcosta.org
www.igorcosta.com
skype: igorpcosta