Using Reporting Parameter for fun and profit

The new Pentaho Reporting 3.8 is the fourth release in a row where parameter played a important role. After ironing out all the easy problems, we are now in a state where we can think about creatively abusing the system.

There is one questions in the support centres that get repeated over and over again.

How do I limit the visible output types for a particular report?

Up until now, there was no sane answer. You either take it all, or you lock the report down to a single output type. But selecting just HTML and PDF, that was impossible.

The desired output for a report is controlled by the “output-target” parameter. The values for this parameter are defined somewhere deep inside the reporting engine. Every output target has its unique identifier, that tells both the type of the export (pageable or table) as well as the actual content type that is generated (text, html, pdf, and so on).

Output-target Description
table/html;page-mode=stream HTML as a single page, all report pagebreaks are ignored
table/html;page-mode=page HTML as a sequence of physical pages, manual and automatic pagebreaks are active
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;page-mode=flow Excel 2007 XLSX Workbook
table/excel;page-mode=flow Excel 97 Workbook
table/csv;page-mode=stream CSV output
table/rtf;page-mode=flow Rich-Text-Format
pageable/pdf PDF output
pageable/text Plain text
pageable/xml Pageable layouted XML
table/xml Table-XML output
pageable/X-AWT-Graphics;image-type=png A single report page as PNG
mime-message/text/html Mime-Email with HTML as body text and all style and images as inline attachments

Since Pentaho Reporting 3.8, we check whether the current report defines one of the known system parameter. If you define your own representation of such a parameter, we use your definition instead of the built-in ones.

Using that knowledge, it is easy to create a list parameter that defines a subset of the available output types. Drop your selection into a table-datasource, and define the parameter as one of the single-selection list-parameter types.

Server Side Printing

You can also invoke server side printing directly from the parameter UI without having to go through an XAction. Define a boolean parameter by creating a table with the following entries:

ID Value
false Do Not Print
true Print

Make sure you set the default value of your parameter to “false” or make false the first selection in your list, or you are likely to trigger printing involuntarily. Save the trees and so on.

If you want to print to a specific printer, you can do so by defining the “printer-name” parameter as well. And with the magic of the scriptable datasource, you can populate it with all known printers:

import javax.print.DocFlavor;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import javax.print.attribute.standard.PrinterName;

import org.pentaho.reporting.engine.classic.core.modules.misc.tablemodel.TableModelInfo;
import org.pentaho.reporting.engine.classic.core.util.TypedTableModel; 


    PrintService[] services = PrintServiceLookup.lookupPrintServices(
        DocFlavor.SERVICE_FORMATTED.PAGEABLE, null);
    TypedTableModel tt = new TypedTableModel();
    tt.addColumn("ID", String.class);
    tt.addColumn("Value", String.class);
    for (int i = 0; i < services.length; i++)
    {
      PrintService service = services[i];
      PrinterName displayName = service.getAttribute(PrinterName.class);
      if (displayName != null)
      {
        tt.addRow(new Object[]{service.getName(), displayName.getValue()});
      }
      else
      {
        tt.addRow(new Object[]{service.getName(), service.getName()});
      }
    }
    return tt;
 
This entry was posted in Advanced Topic, BI-Server, Parameter, Tech-Tips on by .
Thomas

About Thomas

After working as all-hands guy and lead developer on Pentaho Reporting for over an decade, I have learned a thing or two about report generation, layouting and general BI practices. I have witnessed the remarkable growth of Pentaho Reporting from a small niche product to a enterprise class Business Intelligence product. This blog documents my own perspective on Pentaho Reporting's development process and our our steps towards upcoming releases.

8 thoughts on “Using Reporting Parameter for fun and profit

  1. Thomas Morgner

    What properties file? This article does not mention any. If you are seeking the global configuration, then that can be found in the “pentaho/WEB-INF/classes” directory and in “PRD/resources”.

  2. sid

    Hi all.

    I have an issue on how to limit the output type in pentaho report. After I followed this I cannot see any change. I put same name on everything as the image shows. Is there something I missed? Or any other way to limit the visible output type?
    Let me know your idea. Thanks

  3. arnoldVillasanta

    Hi Thomas,

    Thanks for the tip I was able to trim the selection into paged-HTML, excel and PDF.
    There was no problem on the first run of the report right after it was published in BI Server 3.8

    However, after revisiting the reports the next day, all of them has this “This parameter is mandatory” message in the Output Target Dropdown list.

    The Mandatory Field and Validate Field check boxes of this parameters are NOT checked.
    Also, I set the auto-submit in PRD to false.
    I also inject autoSubmit=false in the RUN tag in plugin.xml.

    I hope you can help me with this one.

    Environment:
    PRD 3.6
    BI 3.8

  4. Bikash Kumar

    Hi, I am using PRD 3.8.1 and I have added Excel 2007 manually for the export drop down,I get report with extension xlsx when download using this Excel 2007 export option.

    Problem is, when I schedule and send report in email with export option as Excel 2007. I get attachment without the xlsx and I need to manually rename and need to add xlsx.

    Is there any way that I do not have to rename when exporting Excel 2007 while scheduling it?

    Thanks

Comments are closed.