File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Jasper Report Printing From a Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Jasper Report Printing From a Servlet" Watch "Jasper Report Printing From a Servlet" New topic

Jasper Report Printing From a Servlet

Suraj Batuwana

Joined: Mar 03, 2005
Posts: 3
Hi ,

I have used Jasper Reports to Print from the Servlet
My code is as follows

DocFlavor flavor = DocFlavor.INPUT_STREAM.POSTSCRIPT;
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
PrintService[] pservices = PrintServiceLookup.lookupPrintServices( flavor, aset);
if (pservices.length > 0) {
DocPrintJob pj = pservices[0].createPrintJob();
JasperPrint jPrint = JasperFillManager.fillReport("Test.jasper",parameters,getConnection());
JasperPrintManager.printReport(jPrint, false);

But I have experience the following exception as

net.sf.jasperreports.engine.JRException: Invalid page index range : 0 - -1 of 0
at net.sf.jasperreports.engine.print.JRPrinterAWT.printPages( )
at net.sf.jasperreports.engine.print.JRPrinterAWT.printPages( )
at net.sf.jasperreports.engine.JasperPrintManager.printPages(JasperPrintManager.ja va:392)
at net.sf.jasperreports.engine.JasperPrintManager.printReport(JasperPrintManager.j ava:283)

Any idea on this ?

Or Does any body know any other web based printing methods?

Thanks & Regards,
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

I am going to move this thread to the Other Open Source Forum. Your question is about JasperReports and not a Servlets direct question.



Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
I agree. Here's the link:
subject: Jasper Report Printing From a Servlet
jQuery in Action, 3rd edition