The following code shows how to print all the logical pages of a graph, when you use the
print
method of the GraphPrinter
. This assumes that you have a graph
named myGraph
.
GraphPrinter printer = new GraphPrinter(myGraph); //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 so that the graph fills the sheet of paper printer.setPrintScaleType(GraphPrinter.SCALE_TO_FIT_FULL_PAGE); //set the range to print all logical pages printer.setRangeType(ViewPrinter.ALL_LOGICAL_PAGES); //set the header and footer //this example creates the HeaderAndFooterPainter for readability //you do not have to create one HeaderAndFooterPainter leftHeader = printer.getHeaderAndFooterPainter(ViewPrinter.HEADER_LEFT); leftHeader.setContentType(HeaderAndFooterPainter.PAGE_NUMBER); HeaderAndFooterPainter leftFooter = printer.getHeaderAndFooterPainter(ViewPrinter.FOOTER_LEFT); leftFooter.setContentType(HeaderAndFooterPainter.STRINGS); //create an array of Strings to display in the left footer String[] lFooters = new String[2]; lFooters[0] = "This is my graph"; lFooters[1] = "Created by me"; leftFooter.setStrings(lFooters); //print the graph; 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(); } }