crazybugs Posted April 16, 2009 Share Posted April 16, 2009 After generating a report, change the settings in the JasperViewer window by selecting the "Fit Page" or the "Fit Width" buttons at the top. Select the Printer Icon in the JasperViewer and print. The report does not fit to page while getting printed. Please inform if this issue is resolved in the latest jasper version. Link to comment Share on other sites More sharing options...
lucianc Posted April 17, 2009 Share Posted April 17, 2009 The JasperViewer buttons have no effect on printing, they are only meant to affect the zoom ratio at which the report is displayed in the viewer.Regards,Lucian Link to comment Share on other sites More sharing options...
crazybugs Posted April 20, 2009 Author Share Posted April 20, 2009 The problem is that the report generated in jasper viewer is larger than A4 size.So when I try to print it in A4 paper,some of the data in the reports go missing.Is there any option by which I can fit the size to A4 and print the report from jasper viewer? Thanks in advance.Post Edited by crazybugs at 04/20/2009 15:14 Link to comment Share on other sites More sharing options...
lucianc Posted April 22, 2009 Share Posted April 22, 2009 crazybugsWrote: Is there any option by which I can fit the size to A4 and print the report from jasper viewer? No, JasperViewer cannot do this.This would be possible by using JRPrintServiceExporter with a JRGraphics2DExporterParameter.ZOOM_RATIO parameter. You could also try to extend JRViewer and override the btnPrintActionPerformed method to change the way the report is printed to achieve this.Regards,Lucian Link to comment Share on other sites More sharing options...
crazybugs Posted April 23, 2009 Author Share Posted April 23, 2009 Lucian,Can you provide any sample code for the same.Thanks in advance. Link to comment Share on other sites More sharing options...
lucianc Posted April 24, 2009 Share Posted April 24, 2009 I don't have sample code for this. If you're not willing to try to implement this yourself, post this as a feature request and we will consider it.Regards,Lucian Link to comment Share on other sites More sharing options...
crazybugs Posted April 24, 2009 Author Share Posted April 24, 2009 I had tried the following code mentioned below.But it did not yield any result.Can you please let me know if I had missed out anything?Code used:PrinterJob job = PrinterJob.getPrinterJob(); PageFormat pf = new PageFormat(); Paper pp = new Paper(); pf.setPaper(pp); double ht = jasperPrint.getPageHeight(); double wt = jasperPrint.getPageWidth(); double wt1 =job.defaultPage().getImageableWidth(); double ht1= job.defaultPage().getImageableHeight(); if(ht1<ht){ pp.setSize(ht, wt); } /* Create an array of PrintServices */ PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null); int selectedService = 0; /* Scan found services to see if anyone suits our needs */ for(int i = 0; i < services.length;i++){ if(services.getName().toUpperCase().contains("Your printer's name")){ /*If the service is named as what we are querying we select it */ selectedService = i; } } job.setPrintService(services[selectedService]); job.defaultPage(pf); PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet(); MediaSizeName mediaSizeName = MediaSize.findMedia(4,4,MediaPrintableArea.INCH); printRequestAttributeSet.add(mediaSizeName); printRequestAttributeSet.add(new Copies(1)); JRPrintServiceExporter exporter; exporter = new JRPrintServiceExporter(); exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); /* We set the selected service and pass it as a paramenter */ exporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE, services[selectedService]); exporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE_ATTRIBUTE_SET, services[selectedService].getAttributes()); exporter.setParameter(JRPrintServiceExporterParameter.PRINT_REQUEST_ATTRIBUTE_SET, printRequestAttributeSet); exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PAGE_DIALOG, Boolean.TRUE); exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG, Boolean.TRUE); exporter.setParameter(JRGraphics2DExporterParameter.ZOOM_RATIO, new Float(realZoom)); exporter.exportReport(); Post Edited by crazybugs at 04/24/2009 15:02 Link to comment Share on other sites More sharing options...
erikd Posted July 19, 2011 Share Posted July 19, 2011 Is this still currently not possible? 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