Jump to content

"Fit Page" button does not function in jasper view


crazybugs

Recommended Posts

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

  • Replies 7
  • Created
  • Last Reply

Top Posters In This Topic

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

crazybugs
Wrote:

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

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

  • 2 years later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...