The following code shows how to print all the logical pages of a crosstab, when you use the
print
method. This assumes that you have a crosstab named
myCrosstab
.
This example shows how to print all logical pages of a crosstab, fitting each logical page on four physical pages. Each logical page will fit on two pages vertically and on two pages horizontally.
CrosstabPrinter printer = new CrosstabPrinter(myCrosstab); // invoke the standard Print dialog box if (printer.showPrintJob()){ // set the margins printer.setLeftMargin(78); printer.setTopMargin(50); printer.setBottomMargin(30); printer.setRightMargin(50); // set the scale type to fit each logical page on two pages // vertically and two horizontally printer.setPrintScaleType(ViewPrinter.SCALE_TO_FIT_PAGES); printer.setFitToNumPagesTall(2); printer.setFitToNumPagesWide(2); // set the range to print all logical pages printer.setRangeType(ViewPrinter.ALL_LOGICAL_PAGES); // display two strings in the left header // this example creates a HeaderAndFooterPainter for readability // you do not have to create one HeaderAndFooterPainter leftHeader = printer.getHeaderAndFooterPainter(ViewPrinter.HEADER_LEFT) // headers display strings by default, // so it is not necessary to set contentType here // create an array of Strings to display String[] lHeaders = new String[2]; lHeaders[0] = "This is my crosstab"; lHeaders[1] = "Created by me"; leftHeader.setStrings(lHeaders); // set the footer -- again a HeaderAndFooterPainter for readability HeaderAndFooterPainter leftFooter = printer.getHeaderAndFooterPainter(ViewPrinter.FOOTER_LEFT); leftFooter.setContentType(HeaderAndFooterPainter.PAGE_NUMBER); // print the crosstab; pass true to print method // because we are not sharing the print job with another object // startPrint returns false if no data is available in the view if(printer.startPrint()){ printer.print(true); printer.endPrint(); } // end if startPrint } // end if showPrintJob