Java Reference
In-Depth Information
many pixels in the report to map to a character in the exported text. This is because
the exported text is basically a bunch of pixels, and the JasperReports engine does
not directly recognize the characters in it. By specifying the CHARACTER_WIDTH and
CHARACTER_HEIGHT parameters, the engine can make an educated guess on how to
map the pixels to ASCII characters.
An alternative way of helping JasperReports map report pixels to ASCII characters
is to specify the page width and page height of the exported report. This can be
achieved by setting the JRExportParameter.PAGE_WIDTH and JRExportParameter.
PAGE_HEIGHT parameters to appropriate values on JRTextExporter .
Either the page width and height or the character width and height (or both) must
be specified when exporting to plain text. If both page and character dimensions are
specified, the character dimensions take precedence.
Since the algorithm JasperReports uses to generate plain text
reports maps pixels to ASCII characters, the conversion is not
always 100% accurate. In most cases, report templates must be
modified in order for them to be successfully exported to text.
For these reasons, we recommend avoiding exporting reports to
plain text unless absolutely necessary.
Directing HTML Reports to a Browser
In previous chapters, we have seen examples of generating a PDF report and
streaming it to the browser on the fly. Earlier in this chapter, we saw how to
export reports to an HTML format and store it in the file system. In this section, we
will cover how to export a report to HTML and immediately send it to the user's
browser window. The following example is a servlet that exports an already filled
JasperPrint object to HTML and displays the resulting exported report to the
browser. As can be seen from the code, it takes the base report name as a request
parameter. Executing this report using the BarChartDemoReport from Chapter 7
results in the following page displayed in the browser.
package net.ensode.jasperbook;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
Search WWH ::




Custom Search