Output as PDF (Java)

Set up and configure output to PDF from your reporting application. This option is useful if you want to archive or mail a document.

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

Example

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

String designFile = "OrderReport.4rp";
String outputFilename = "SalesList.pdf";
    
FormatHandler handler = new FormatWriter(outputFilename);
PDFRenderer renderer = new PDFRenderer(handler);
renderer.setJPEGQuality(0.5);
FourRpLayouter report = new FourRpLayouter(designFile, renderer);

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

// some code omitted - view full source in demo

report.runFromJAXBObject(data);
    
// open the file
File result = new File(outputFilename);
Desktop desktop = Desktop.getDesktop();
desktop.open(result);

// code snippet ends
In this example:
  • A FormatHandler object named handler is defined using the FormatWriter class, taking the name of the output file as its input.
  • An object named renderer is defined using the PDFRenderer class, taking handler as input.
  • The setJPEGQuality method sets the compression quality of any included JPEG image to a value between 0 and 1. A compression quality setting of 0.0 is interpreted as "high compression is important," while a setting of 1.0 is interpreted as "high image quality is important."
  • FourRpLayouter report = new FourRpLayouter(designFile, renderer) creates the FourRpLayouter object for the specified report file that outputs a PDF file with the provided name.

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