2002 JI Open Discussion Posted August 18, 2006 Share Posted August 18, 2006 By: Oleg - oleg_vn How to Print Lanscape Report 2002-12-17 05:25 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 By: Claudio Pi - claudiopi RE: How to Print Lanscape Report 2003-09-11 12:28 I'm having the exact same problem trying to set the printer margins without the print dialog box: I'm getting the Exception: "No suitable print service found.". I notice you are setting the MediaPrintableArea (in the JRPrintServiceExporter) after you get the PrintService array. If I try executing the exact same code before getting the services I got services.length==0 and then the exception is thrown !! Any solution or workaround for this problem ? Thanks in advance, Claudio. 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