Design Document: Export to PDF and HTML with Jasper Reports
Currently there is just one hardcoded "template" of PDF report in GanttProject. Customization options basically come down to the choice of task/resource columns to be exported. We want to allow for building of arbitrary reports with layout and data chosen by the report designer. We want to use industry standard solution for report templates rather than our own home grown technology. Jasper Reports seems to be a reasonable choice for that.
We'd like to keep the current user interface of PDF/HTML with probably small modifications. PDF and HTML exports appear next to each other in the list of exporters in the Export Wizard.
Both HTML and PDF exports allow for choosing export theme in the UI. The list of themes may come from different engines.
Current HTML engine is based on XSL transformations and doesn't provide any additional configuration options. It has three themes.
Current PDF engine is based on iText and provides additional UI for choosing the date range to be exported, page format and font substitution. These options may be useful for JasperReports based export as well.
The stack of abstractions looks roughly as follows:
-
ExporterToPDF
is an implementation ofExporter
extension point which plugs into the Export Wizard. It contains export engine(s). Most likely JasperReports-based export should be implemented as engine contained in this class. -
ITextEngine
actually is not dealing with iText library. It provides additional UI and controls the process of scanning available TrueType fonts. Its code might be useful and it may make sense to extract common superclass for iText and JasperReports engines.ITextEngine
receives the theme selected by the user throughsetSelectedStylesheet
method. -
ThemeImpl
which is the implementation ofStylesheet
interface is actually driving the process of export to PDF. Its code is most likely not relevant to JasperReports, although some utility functions might be useful.
PDF and HTML exports use essentially different ways of translating project model into reports. PDF export directly translates the project model represented by IGanttProject
instance into iText entities in Java code. HTML export serializes the project model to XML (which is different from XML in GanttProject project files) and runs XSL transformations over the serialized data. In theory, users can write their own XSL transformations.
We want to provide ability to write custom reports, so the approach which is used by current PDF export is not an option as users will not write Java code. Consequently, we need to provide some data source to JasperReports engine and let users extract data from the data source using whatever is available in JasperReports.
We migrate the internal data structures to Google Protocol Buffers, and it is possible to feed both JSON and XML to JasperReports by serializing an instance of biz.ganttproject.impex.ExportProtos.Project
class. Serialization of IGanttProject
instance to JSON looks as follows:
import net.sourceforge.ganttproject.io.ExportSerializer;
import net.sourceforge.ganttproject.io.ModelSerializerKt;
...
ModelSerializerKt.asJson(new ExportSerializer(project).write());
For demo purposes it is built into AbstractEngine.setContext
method which is called when user chooses export to PDF in the wizard and clicks "Next".
This feature should eventually be merged into master
and published in one of the future versions. The base integration branch for pull requests is prj3_master
. Please fork from this base branch and create pull request into this base branch.
We use Java 8 and Kotlin. Feel free to choose the language and feel free to use modern features of Java 8 if needed.
We'll appreciate a few unit tests if possible.
The process is described on GanttProject doc pages. Please do follow the code style and code review process. Your code should be of high quality in both operational and reading aspects (that is, it should work and it should be readable to us), and please be prepared to pretty demanding code review.