Varying pagination in different formats of a report - jasper-reports

Using iReport, I am generating reports to be viewed in multiple formats. Is it possible for me to ignore pagination only for particular formats like HTML and let it be true for the rest?
With isIgnorePagination="false" the HTML preview appears in chunks. However, setting it to true makes the PDF output a single page.
Any suggestions?

Why yes you can. Add the the IS_IGNORE_PAGINATION with the appropriate value before you export your report. You can set the value at run time based on what your export format is.
params.put("IS_IGNORE_PAGINATION", true);

I found one solution for this problem:
paramaters.put("fromDate", fromDate);
paramaters.put("toDate", toDate);
if (!output.equals("pdf"))
{
paramaters.put("IS_IGNORE_PAGINATION", true);
}
else
paramaters.put("IS_IGNORE_PAGINATION", false);
JasperPrint jasperPrint = null;
jasperPrint = JasperFillManager.fillReport(CompiledReport, paramaters, connection);
if (output.equals("html")) {
generateHtmlResponse(response, jasperPrint);
} else if (output.equals("pdf")) {
generatePdfResponse(response, jasperPrint);
} else if(output.equals("excel")) {
generateXLResponse(response, jasperPrint);
}

Related

Getting 3 mins to Generate the Jasper Report

I am developing the Invoice printing System using the Jasper report, Now I have can print the report but it will take 2000ms to load the report, also 2000ms take to start the printing,
These are I am using the JAR FILES,
commons-beanutils-1.4
commons-digester-1.7
commons-logging-1.0.3
commons-beanutils-1.4
groovy-all-1.7.5
batik-all-1.7
barcode4j-2.1
itextpdf-5.1.0
jasperreports-6.0.3
xercesImpl-2.11.0
xml-apis-ext-1.3.04
preparedStatement = conn.prepareStatement(sqlString);
resultSet = preparedStatement.executeQuery();
if (resultSet.next()) {
HashMap<String, Object> hm = new HashMap<>();
JasperDesign jasperDesign = JRXmlLoader.load(new File(
"C:/Invoice/Invoice.jrxml"));
JRDesignQuery designQuery = new JRDesignQuery();
designQuery.setText(sqlString);
jasperDesign.setQuery(designQuery);
JasperReport jasperReport = JasperCompileManager
.compileReport(jasperDesign);
JasperPrint jasperPrint = JasperFillManager.fillReport(
jasperReport, null, conn);
for (int i = 0; i < copies; i++) {
JasperPrintManager.printReport(jasperPrint, false);
}
JasperViewer.viewReport(jasperPrint);
The above code I used to print the report but, getting too much time to load the report. Please suggest my fault and some other idea...
I guess the SQL query could be the problem. Have you tried executing it in a sql query tool and check how long it runs? Optimizing it should yield a performance win.
You are also running the query twice: before the report and when you are filling it via the JasperFillManager.fillReport() call.
If there are no specific reasons to check wheter the query contains any records, I would recommand to let JasperReports handle the query and the case that no record is found. You can determine a specific behaviour in that case via the "When No Data Type" property in the reportdesign.

How to store and compare annotation (with Gold Standard) in GATE

I am very comfortable with UIMA, but my new work require me to use GATE
So, I started learning GATE. My question is regarding how to calculate performance of my tagging engines (java based).
With UIMA, I generally dump all my system annotation into a xmi file and, then using a Java code compare that with a human annotated (gold standard) annotations to calculate Precision/Recall and F-score.
But, I am still struggling to find something similar with GATE.
After going through Gate Annotation-Diff and other info on that page, I can feel there has to be an easy way to do it in JAVA. But, I am not able to figure out how to do it using JAVA. Thought to put this question here, someone might have already figured this out.
How to store system annotation into a xmi or any format file programmatically.
How to create one time gold standard data (i.e. human annotated data) for performance calculation.
Let me know if you need more specific or details.
This code seems helpful in writing the annotations to a xml file.
http://gate.ac.uk/wiki/code-repository/src/sheffield/examples/BatchProcessApp.java
String docXMLString = null;
// if we want to just write out specific annotation types, we must
// extract the annotations into a Set
if(annotTypesToWrite != null) {
// Create a temporary Set to hold the annotations we wish to write out
Set annotationsToWrite = new HashSet();
// we only extract annotations from the default (unnamed) AnnotationSet
// in this example
AnnotationSet defaultAnnots = doc.getAnnotations();
Iterator annotTypesIt = annotTypesToWrite.iterator();
while(annotTypesIt.hasNext()) {
// extract all the annotations of each requested type and add them to
// the temporary set
AnnotationSet annotsOfThisType =
defaultAnnots.get((String)annotTypesIt.next());
if(annotsOfThisType != null) {
annotationsToWrite.addAll(annotsOfThisType);
}
}
// create the XML string using these annotations
docXMLString = doc.toXml(annotationsToWrite);
}
// otherwise, just write out the whole document as GateXML
else {
docXMLString = doc.toXml();
}
// Release the document, as it is no longer needed
Factory.deleteResource(doc);
// output the XML to <inputFile>.out.xml
String outputFileName = docFile.getName() + ".out.xml";
File outputFile = new File(docFile.getParentFile(), outputFileName);
// Write output files using the same encoding as the original
FileOutputStream fos = new FileOutputStream(outputFile);
BufferedOutputStream bos = new BufferedOutputStream(fos);
OutputStreamWriter out;
if(encoding == null) {
out = new OutputStreamWriter(bos);
}
else {
out = new OutputStreamWriter(bos, encoding);
}
out.write(docXMLString);
out.close();
System.out.println("done");

CSV export repeats headers with each field value

I know this is going to be a really simple answer... when I export my header comes out on each export line preceding the fields that are being exported. I want the header line to export in csv in the 1st line, with the record lines underneath.
When you select CSV as your export option it'll open a new dialog box. In it, note the Report and Page Sections section. Leave it set to Export but be sure to check Isolate Report/Page sections. It'll then work how you'd expect.
You can display the crystal reports as CSV files in the same way as they appear in reports by doing the below thing. This will export into pdf excel or word in exactly same way you want to display
string contentType = "";
ExportOptions options = new ExportOptions();
switch (formatType.ToLower())
{
case "pdf":
default:
options.ExportFormatType = ExportFormatType.PortableDocFormat;
contentType = "application/pdf";
break;
case "excel":
options.ExportFormatType = ExportFormatType.Excel;
contentType = "application/vnd.ms-excel";
break;
case "csv":
contentType = "application/csv";
options.ExportFormatType = ExportFormatType.CharacterSeparatedValues;
//CharacterSeparatedValuesFormatOptions v= ExportOptions.CreateCharacterSeparatedValuesFormatOptions();
//v.SeparatorText
options.ExportFormatOptions = new CharacterSeparatedValuesFormatOptions()
{
ExportMode = CsvExportMode.Standard,
GroupSectionsOption= CsvExportSectionsOption.ExportIsolated,
ReportSectionsOption = CsvExportSectionsOption.ExportIsolated
};
break;
}
This discussion suggests a couple options:
Export to Excel first, then save as CSV
Modify some registry keys
http://sagecity.na.sage.com/support_communities/sage100_erp/f/97/p/38336/125272

jasper reports with HTML Format

Am using jasper reports library with GWT application.
The reports is generated well with CSV format but with HTML format it generate the HTML page with icons of missing picture.
I know that jasper using transparent image called "PX", this image not found.
How can i solve this problem?
Thanks in Advance
If you don't have images to show then you can do this:
JasperPrint jasperPrint = JasperFillManager.fillReport(path, parameters, con);
JRHtmlExporter htmlExporter = new JRHtmlExporter();
response.setContentType("text/html");
request.getSession().setAttribute(ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE, jasperPrint);
htmlExporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
htmlExporter.setParameter(JRExporterParameter.OUTPUT_WRITER, out);
htmlExporter.setParameter(JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN, false);
htmlExporter.exportReport();
The important line is this one:
htmlExporter.setParameter(JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN, false);
That will make all the "px" images disappear.
Try passing in your image as a parameter to the report so you won't have to worry about image paths.
You can set the type of the parameter as a BufferedImage or whatever image class suits.
My solution was to use data URIs. This isn't very elegant since it bloats the size of the HTML and doesn't work in IE prior to IE8, but it does allow you to not bother worrying about creating files out of the image attachments Jasper sends you either.
If you're going to implement this, you want to add this argument to your request:
<argument name="IMAGES_URI"><![CDATA[data:]]></argument>
Then you need to parse the report HTML that JasperServer sends back:
foreach ($attachments as $name => $attachment) {
// Cut off the cid: portion of the name.
$name = substr($name, 4);
// Replace any image URIs with a data: uri.
if (strtolower(substr($name, 0, 4)) !== 'uuid' && strtolower($name) !== 'report') {
if (strtoupper(substr($attachment, 0, 3)) === 'GIF') {
// It's a GIF.
$report = str_replace("data:$name", 'data:image/gif;base64,' . base64_encode($attachment), $report);
} elseif (/* more file type tests */) {
// and so on...
}
}
}
For large images, it's best to do as Gordon suggested and pass in a parameter specifying the URL of a file that is permanently stored on the server. This method is more of a failsafe for gracefully handling any unexpected images JasperServer tries throwing at you.
I'm a bit late to this discussion but this is what I've been using. The key is to pass the imagesMap to both the session attribute and exporter parameter, and to set the IMAGES_URI exporter parameter.
private void exportReportAsHtml(HttpServletRequest request, HttpServletResponse response, JasperPrint jasperPrint) throws IOException, JRException {
response.setContentType("text/html");
request.getSession().setAttribute(ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE, jasperPrint);
Map imagesMap = new HashMap();
request.getSession().setAttribute("IMAGES_MAP", imagesMap);
JRHtmlExporter exporter = new JRHtmlExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_WRITER, response.getWriter());
exporter.setParameter(JRHtmlExporterParameter.IMAGES_MAP, imagesMap);
exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, "image?image=");
exporter.exportReport();
}

how do you set the default export name in the crystal report viewer

On an ASP.NET page, when a user is viewing a report from the Crystal Report Viewer(CRV) they have the ability to export the report (eg to PDF). The default filename for the export is the ID of the CRV.
I would like to set the default name to be something that is based on the parameters of the report. (eg "Sales for 2008").
I know I can add a link to the page that would and then I could code up a solution where I generated the PDF in code and the stream it to the browser, but I was hoping there might be a way to do this nativity in Crystal Reports.
// You could pass the parameters to the web page
// where you have theCrystalReportViewer control
protected void Page_Load(object sender, EventArgs e)
{
string reportId = Request["rid"];
string reportTitle = Request["rtitle"];
ReportDocument reportDocument = HttpContext.Current.Session[reportId] as ReportDocument;
this.CommonCrystalReportViewer.ReportSource = reportDocument;
this.CommonCrystalReportViewer.DataBind();
// Set the default export file name for the report.
this.CommonCrystalReportViewer.ID = reportTitle;
}
If you are using Visual Studio 2008 to create the report you could edit the ReportClass created to add your DefaultName property.
Natively there was a ReportExporter class to be used instead of ReportViewer class but it's not supported anymore. There are some third-parts similar.
I use this code samples:
Get parameters value from report (if you don't have already from Session, QueryString or somewhere else)
string myParamName="XXX";
object myParamValue;
foreach (ParameterField field in reportDocument.ParameterFields)
{
if (string.Compare(field.Name.TrimStart('#'), myParamName, true) == 0)
myParamValue= field.CurrentValues;
}
Export using report name needed
string myReportName = "sales for " + myParamValue.ToString() + ".pdf";
try
{
reportDocument.ExportToHttpResponse(
ExportFormatType.PortableDocFormat
,Response, true, myReportName);
}
catch (System.Threading.ThreadAbortException)
{
//System.Threading.ThreadAbortException is thrown
//because, Response.End is called internally in ExportToHttpResponse method:
}
protected void Page_Init(object sender, EventArgs e) {
...
// Set the default export file name for the report.
this.mainReportViewer.ID = reportTitle;
...
}
It is mandatory to change reportViewer id in Page_Init function, otherwise will not work.