views:

59

answers:

1

Hi,

I have a jasper report that I'm displaying. Now I have an icon to get the same report in PDF.

Now when I deploy the code in an OS with Tomcat it works fine, but the problem I'm facing now is that, we have created a VM Image of Ubuntu without UI.

And when I try to download the report as PDF, i get an error, after extensive search on the Web and here, I found that the fonts were missing and hence this problem.

Now I've hard-coded the path of the font and put the true-type font also in the same path of the report folder. But still I'm getting an error.

Here is the code I've put in the JRXML file

<font size="20" isBold="false" fontName="Verdana" pdfFontName="/var/lib/tomcat6/webapps/WallCloud/jsp/dashboard/reports/Helvetica.ttf" isBold="false" isPdfEmbedded ="true"/>

and here is the error I'm getting

javax.servlet.ServletException: org.apache.jasper.JasperException: javax.servlet.ServletException: java.lang.NoClassDefFoundError: Could not initialize class net.sf.jasperreports.engine.util.JRStyledTextParser
    org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:515)

This is on a the line

JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, null, conn);

And here is my pdf generation code

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.sql.Connection" %>
<%@page import="net.sf.jasperreports.view.JasperViewer" %>
<%@page import="net.sf.jasperreports.engine.xml.JRXmlLoader" %>
<%@page import="net.sf.jasperreports.engine.JasperCompileManager" %>
<%@page import="net.sf.jasperreports.engine.JasperFillManager" %>
<%@page import="net.sf.jasperreports.engine.JasperPrint" %>
<%@page import="net.sf.jasperreports.engine.design.JasperDesign" %>
<%@page import="net.sf.jasperreports.engine.JasperReport" %>
<%@page import="java.io.ByteArrayOutputStream" %>
<%@page import="com.abc.xyz.utils.DBConnection" %>
<%@page import="org.apache.commons.collections.*" %>
<%@page import="org.apache.jasper.JasperException" %>

<form name='frmReport' method='POST'>
    <%
    try {
        Connection conn = null;
        DBConnection dbConn = new DBConnection();
        conn = dbConn.getSimpleConnection();
        String path = getServletContext().getRealPath("/")+"/jsp/reports/Report.jrxml";


      JasperDesign jasperD = JRXmlLoader.load(path);
            JasperReport jasperReport = JasperCompileManager.compileReport(jasperD);
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            response.setContentType("application/pdf");
            response.setHeader("Content-Disposition", "inline; filename=\"Report.pdf\"");   
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, null, conn);
                    net.sf.jasperreports.engine.JasperExportManager.exportReportToPdfStream(jasperPrint, baos);

                response.setContentLength(baos.size());
            ServletOutputStream out1 = response.getOutputStream();
            baos.writeTo(out1);

            out1.flush();
            conn.close();
        } catch (Exception se) {

        }
    %>

How can I resolve this issue?

A: 

I found the solution to this problem. We need the following:

  1. Edit /etc/apt/sources/list

  2. add the following line

    deb http://us.archive.ubuntu.com/ubuntu/ hardy multiverse

    deb-src http://us.archive.ubuntu.com/ubuntu/ hardy multiverse

    deb http://us.archive.ubuntu.com/ubuntu/ hardy-updates multiverse

    deb-src http://us.archive.ubuntu.com/ubuntu/ hardy-updates multiverse

  3. sudo apt-get update

  4. sudo apt-get install msttcorefonts

This solves the problem and the PDF is also getting generated.

Panther24