2006 IR Open Dicussion Posted August 27, 2006 Share Posted August 27, 2006 By: Shikha Meena - shikhameena Printing Issue - Jasper Report 2006-05-12 07:51 Hi , In our project we are using jasperreports-1.2.0. The requirement in our project is such that the .jrprint file can be used to print on one of the network printer. To achieve this functionality I have written following code : - public void jasperPrint(PrintJobDTO prJobDto ,String fileName, UserSessionDataDTO argUserSessionDataDTO , String printerCode) { try { JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(fileName); System.out.println( "jasperPrint >>>> "+ jasperPrint.getOrientation()); AttributeSet aset = new HashAttributeSet(); aset.add(new PrinterName(printerCode, null)); PrintService[] services = PrintServiceLookup.lookupPrintServices(null, aset); PrintService service = null; for (int i = 0; i < services.length; i++) { service =services; System.out.println( "service >>>> "+ service); System.out.println( "service.getName() >>>> "+ service.getName() ); break; } System.out.println("New jasperPrint fileName >> " + fileName ); PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet(); printRequestAttributeSet.add(new Copies(prJobDto.getNumberOfCopies())); printRequestAttributeSet.add(OrientationRequested.LANDSCAPE); printRequestAttributeSet.add(MediaSizeName.ISO_A4); System.out.println("before printer code >> " + printerCode); printRequestAttributeSet.add( new MediaPrintableArea( 0f, 0f, 11.694f, 8.264f, MediaPrintableArea.INCH )); System.out.println("MediaPrintableArea>> " +(!printRequestAttributeSet.containsKey(MediaPrintableArea.class))); //PrintServiceAttributeSet printServiceAttributeSet = new HashPrintServiceAttributeSet(); //printServiceAttributeSet.add(new PrinterName(printerCode, null)); //System.out.println("after printer code " +printerCode ); JRPrintServiceExporter exporter = new JRPrintServiceExporter(); exporter.setParameter(JRExporterParameter.INPUT_FILE_NAME, fileName); exporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE, service); 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.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); //exporter.exportReport(); System.out.println("Printing END>> " ); } catch(JRException e) { System.out.println( "JRException >>>> "+ e.getMessage()); } catch(Exception e) { e.printStackTrace(); } } But the print out using this method is not proper .It seems to truncate all the text even though the Text fields are set to stretch , the page size and page orientation of the print out is also not correct. Please guide me in resolving this issue. Any suggestions and views are welcome. Many Thanks... Shikha 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