2006 IR Open Dicussion Posted August 17, 2006 Share Posted August 17, 2006 By: Oleg - oleg_vn How to Print Lanscape Report 2002-12-17 06:12 My code: -------------- PrintService[] services = PrinterJob.lookupPrintServices(); for (int i = 0; i < services.length; i++) { jComboBoxPrinter.addItem(services.getName()); } ... PageRanges pRanges= new PageRanges("2,4,6"); try { PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet(); printRequestAttributeSet.add(MediaSizeName.ISO_A4); printRequestAttributeSet.add(pRanges); if (jasperPrint.getOrientation() == JRReport.ORIENTATION_LANDSCAPE) { printRequestAttributeSet.add( OrientationRequested.LANDSCAPE ); } else { printRequestAttributeSet.add( OrientationRequested.PORTRAIT ); } PrintServiceAttributeSet printServiceAttributeSet = services[jComboBoxPrinter.getSelectedIndex()].getAttributes(); JRPrintServiceExporter exporter = new JRPrintServiceExporter(); exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); exporter.setParameter(JRPrintServiceExporterParameter.PRINT_REQUEST_ATTRIBUTE_SET, printRequestAttributeSet); exporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE_ATTRIBUTE_SET, printServiceAttributeSet); exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PAGE_DIALOG, Boolean.FALSE); exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG, Boolean.FALSE); exporter.exportReport(); } catch (JRException ex) { ex.printStackTrace(); } catch (Exception ex) { ex.printStackTrace(); } ------------------- All fine, but printed only part of page. (Left margin = 80.75 cm) I`m added this : printRequestAttributeSet.add( new MediaPrintableArea( 0f, 0f, (float)jasperPrint.getPageWidth() / 72f, (float)jasperPrint.getPageHeight() / 72f, MediaPrintableArea.INCH ) ); and catch Exception : "No suitable print service found." Help me! Oleg Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now