Jump to content
JasperReports Library 7.0 is now available ×

problem with report printing on client side


dgmanu

Recommended Posts

hi ,

am using struts and jasper reports on my project, now i was having problem that whenever i try to print the report , the printer dialogue box was appearing on server machine, i want it on client end, how to solve this problem, please any one know help me, it was urgent,

 

my code was like this

 

Code:
JasperCompileManager.compileReportToFile("c:/report/test.jrxml","c:/report/test.jasper"«»);

JasperPrint jasperPrint = JasperFillManager.fillReport("c:/report/test.jasper"«»),parameters,con);


List l=jasperPrint.getPages();
if(l.size() != 0){
jasperPrint.setOrientation(JasperReport.ORIENTATION_PORTRAIT);
jasperPrint.setPageHeight(877);
jasperPrint.setPageWidth(963);
JasperPrintManager.printPages(jasperPrint,0,l.size()-1,true);
}

 

thanks in advance,

Link to comment
Share on other sites

  • 6 years later...
  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Step 1 : In base Jsp(report.jsp)

input type="hidden" name="contextPath" value="<%=request.getContextPath() %>" id="contextPath"/>

Step 2 : On includesed js(report.js)

var contextPath=document.getElementById("contextPath").value; var url=contextPath+"/generateRecptReport.do?method=generateRecptReport; popupWin= window.open(url,'Report','menubar, toolbar, location, directories, status, scrollbars, resizable, dependent, width=1, height=1 left=0, top=0');

Step 3 on struts-config.xml file

 

**Step 4 on Action(Java code)(ReceiptMakerProcessAction.java)

public ActionForward generateRecptReport(ActionMapping mapping,ActionForm form, HttpServletRequest request,HttpServletResponse response) throws Exception { logger.info("In generateRecptReport");
String p_company_logo=getServlet().getServletContext().getRealPath("/")+"reports/logo.bmp"; String reportPath="/reports/MSSQLREPORTS/"; String reportName="receiptMemoReport";
ReportsDAO reportdao = (ReportsDAO)DaoImplInstanceFactory.getDaoImplInstance(ReportsDAO.IDENTITY); logger.info("Implementation class: "+reportdao.getClass()); reportName=reportdao.getReceiptReportName(); if(CommonFunction.checkNull(reportName).trim().equalsIgnoreCase("")) reportName="receiptMemoReport";

Connection connectDatabase = ConnectionDAO.getConnection();     

    Map<Object,Object> hashMap = new HashMap<Object,Object>();

    hashMap.put("p_company_logo",p_company_logo);

    hashMap.put("IS_IGNORE_PAGINATION",true);

    try

    {

        InputStream reportStream = getServlet().getServletConfig().getServletContext().getResourceAsStream(reportPath+reportName+".jasper");

        JasperPrint jasperPrint = null; 

        PrintWriter out=response.getWriter();

        out.append("<head><script type='text/javascript' src='"+request.getContextPath()+"/js/report/report.js'></script></head>");

        out.append("<body onLoad='self.print();self.close()'></body>");     

        response.setContentType("text/html");       

        String htmlReportFileName=reportName+".html";

        JRHtmlExporter exporter = new JRHtmlExporter();     

        request.getSession().setAttribute(ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE,jasperPrint);     

        exporter.setParameter(JRHtmlExporterParameter.OUTPUT_WRITER, out);

        exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);

        exporter.setParameter(JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN ,Boolean.FALSE);

        exporter.setParameter(JRHtmlExporterParameter.IGNORE_PAGE_MARGINS ,Boolean.TRUE); 

        exporter.setParameter(JRHtmlExporterParameter.IS_WHITE_PAGE_BACKGROUND,Boolean.FALSE);

        exporter.setParameter(JRHtmlExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS,Boolean.TRUE);

        exporter.setParameter(JRHtmlExporterParameter.IS_OUTPUT_IMAGES_TO_DIR, Boolean.TRUE);

        exporter.setParameter(JRHtmlExporterParameter.BETWEEN_PAGES_HTML,"");

        exporter.setParameter(JRExporterParameter.OUTPUT_WRITER, response.getWriter());

        float f1=1.2f;  

        exporter.setParameter(JRHtmlExporterParameter.ZOOM_RATIO ,f1);

        exporter.exportReport();                    

    }

    catch(Exception e)

    {

        e.printStackTrace();

    }

    finally 

    {

        ConnectionDAO.closeConnection(connectDatabase, null);

        hashMap.clear();

    }

    return null;

}

 

Link to comment
Share on other sites

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...