我有一個碧玉報告,我正在顯示。現在我有一個圖標可以用PDF獲取相同的報告。賈斯珀報告+ PDF生成問題
現在,當我使用Tomcat在OS上部署代碼時,它可以正常工作,但現在我面臨的問題是,我們創建了一個沒有UI的Ubuntu虛擬機映像。
而當我嘗試以PDF格式下載報表時,我在Web上進行大量搜索後發現錯誤,並且在此處發現字體丟失,因此出現此問題。
現在我硬編碼了字體的路徑,並將真實類型字體也放在報告文件夾的相同路徑中。但我仍然收到錯誤。
這裏是我已經把在JRXML文件
<font size="20" isBold="false" fontName="Verdana" pdfFontName="/var/lib/tomcat6/webapps/WallCloud/jsp/dashboard/reports/Helvetica.ttf" isBold="false" isPdfEmbedded ="true"/>
這裏的代碼我得到
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)
錯誤這是一個行
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, null, conn);
這裏是我的pdf一代代碼
<%@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) {
}
%>
我該如何解決這個問題?