Output as Browser (Java)

Set up and configure output to a browser from your reporting application. The Browser option provides high fidelity viewing. Silent printing is not available; you must use the Print function in your browser.

To use any of the renderer classes, you must import the com.fourjs.report.runtime package:
import com.fourjs.report.runtime.*;

To view a Web report, you need a Web server. For our demo application, we provide a lightweight Web server. See The OrderReportJava demo.

To output your report in a browser, use the class BrowserViewer.

Example

This code snippet uses the BrowserViewer class:
// code snippet starts

String designFile = "OrderReport.4rp";

//Defining renderer object:
LayoutedPagesConsumer renderer=null;

//Send report to Genero Web Viewer:
BrowserViewer viewer = new BrowserViewer();
String uuid=java.util.UUID.randomUUID().toString();
String webRootDirectory=new File( "." ).getCanonicalPath()+"/HTTPDaemon";
viewer.setDocumentDirectory(webRootDirectory+"/reports/documents/"+uuid);
viewer.setFontDirectory(webRootDirectory+"/reports/documents/fonts");
viewer.setFontFileFormat(BrowserViewer.FontFileFormat.woff);
if (Desktop.isDesktopSupported())
{
    if(httpd==null)
    {
        httpd=new NanoHTTPD(6403,webRootDirectory);
    }

    Desktop desktop = Desktop.getDesktop();
    try
    {
        desktop.browse(new java.net.URI("http://127.0.0.1:6403/reports/viewer/viewer.html?reportId="+uuid));
    }
    catch(java.net.URISyntaxException e)
    {
        throw new RuntimeException(e);
    }
}
renderer = viewer;

FourRpLayouter report = new FourRpLayouter(designFile, renderer);

//Run the report 
report.setDebugLevel(9);

// some code omitted - view full source in demo

report.runFromJAXBObject(data);

// code snippet ends
In this example:
  • An object named renderer is defined using the LayoutedPagesConsumer class.
  • A viewer object is defined using the BrowserViewer class.
  • The String variables uuid and webRootDirectory are created and set.
  • The setDocumentDirectory, setFontDirectory and setFontFileFormat methods configure for the browser viewer.
  • The if statement specifies the lightweight web server to use and the URL to attempt.
  • renderer = viewer sets the renderer object to the viewer object.
Note:

This is from the OrderReport demo, and uses our lightweight web server. You can find the complete code in the demo.

For the full list of methods for this renderer class, refer to the Genero Report Writer Java API documentation.