2006 IR Open Dicussion Posted August 27, 2006 Share Posted August 27, 2006 By: Philippe Damerval - damerval PLEASE HELP - problem creating PDF's 2006-06-09 16:54 Hello, I have a servlet creating PDF's, acting as a print service for database records. My environment is jasper 1.2.1 and all corresponding versions, java 1.5 and tomcat 5.5. When I do not include an image in my report template, the server generates the PDF just fine, with data. When I include an image in the report template, all that is generated is a blank page. From iReport, however, the PDF generates fine with the image in it. I have placed multiple copies of the images used in the template in various locations including the computer root, the tomcat root, the webapps folder, my web print application root, the images folder etc - to no avail. I need this fixed urgently. Does anyone have any idea what may be happening? Thanks Philippe By: Teodor Danciu - teodord RE: PLEASE HELP - problem creating PDF's 2006-06-12 04:14 Hi, Without a stack trace it is hard for anybody to have an idea about what's going wrong. You either come up with a stack trace from the log files or you try use onErrorType="Icon" for your image element. I hope this helps. Teodor By: Philippe Damerval - damerval RE: PLEASE HELP - problem creating PDF's 2006-06-12 12:12 Hi Teodor, thank you so much for looking at this. I would have attached a stack trace if I had one, but unfortunately the call to JasperExportManager.exportReportToPdfFile does not throw any exception. It just generates an empty file when there is an image in the template, and only from the servlet - the images are present when I just generate the PDF from iReport. I have tried setting the onErrorType to "Icon" but I still get a blank PDF as a result. I don't have much to go by. I have included my code for the servlet in case something jumps at you that route. package adfg; import net.sf.jasperreports.engine.*; import net.sf.jasperreports.engine.util.JRLoader; import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.File; import java.io.IOException; import java.io.PrintWriter; import java.sql.*; import java.util.HashMap; import java.util.Map; /** * Created by IntelliJ IDEA. * User: PDamerval * Date: May 17, 2006 * Time: 9:53:29 AM * To change this template use File | Settings | File Templates. */ public class PrintPermit extends HttpServlet { public void service( HttpServletRequest request, HttpServletResponse response ) throws IOException, ServletException { ServletContext context = this.getServletConfig().getServletContext(); response.setContentType("text/html"); PrintWriter out = response.getWriter(); try { String permitNo = request.getParameter("PN"); if (null == permitNo) {throw new ServletException("Permit number must be specified");} String tableName = request.getParameter("TN"); if (null == tableName) {tableName = "I_CAT_PU_PERMIT_PRINT";} System.out.println("Printing permit #" + permitNo + " FROM " + tableName); File reportFile = new File(context.getRealPath("PermitTemplate.jasper")); JasperReport jasperReport = (JasperReport) JRLoader.loadObject(reportFile.getPath()); System.out.println(reportFile.getPath()); Map<String,File> parameters = new HashMap<String, File>(); parameters.put("BaseDir", reportFile.getParentFile()); String jdbcDriver = "oracle.jdbc.driver.OracleDriver"; String databaseUrl = "jdbc:oracle:thin://@hooligan.adfg.state.ak.us:1521:ifdbtest"; String userid = "ifdb"; String password = "ttspy2k"; Connection con = null; Class.forName(jdbcDriver); System.out.println("JDBC Driver Loaded"); con = DriverManager.getConnection(databaseUrl, userid, password); System.out.println("Connection established with " + databaseUrl); if (null != con) { Statement stmt = con.createStatement(); String sql = "SELECT * FROM " + tableName + " WHERE PERMIT_NO = " + permitNo; ResultSet rs = stmt.executeQuery(sql); JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, new JRResultSetDataSource(rs)); JasperExportManager.exportReportToPdfFile(jasperPrint, context.getRealPath("") + "/ " + permitNo + ".pdf"); con.close(); } else { throw new ServletException("No database connection available"); } //System.out.println("Current context home: " + context.getRealPath("")); out.println("<html>"); out.println("<head>"); out.println("<title>ADFG info"); out.println("<link rel="stylesheet" type="text/css" href="../stylesheet.css" title="Style">"); out.println("</head>"); out.println("<body bgcolor="white">"); out.println("<span class="bnew">Report printed successfully</span>"); out.println("</body>"); out.println("</html>"); } catch (Exception e) { out.println("<html>"); out.println("<head>"); out.println("<title>ADFG Error"); out.println("<link rel="stylesheet" type="text/css" href="../stylesheet.css" title="Style">"); out.println("</head>"); out.println("<body bgcolor="white">"); out.println("<span class="bnew">JasperReports encountered this error :</span>"); out.println("<pre>"); e.printStackTrace(out); out.println("</pre>"); out.println("</body>"); out.println("</html>"); throw new ServletException(e.getMessage() + " " + e.getStackTrace()); } } } By: Philippe Damerval - damerval RE: PLEASE HELP - problem creating PDF's 2006-06-12 12:50 One more thing: Teodor, I'd love to spend money at Jaspersoft paying for a support incident, as this is quite urgent, but when I call the support number they refer me back to the office because I don't have a support contract, and when I contact the office all I get is a voice mailbox, and they don't return messages. I thought you'd want to know this, if you are working with those people. Thanks, Philippe Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now