Hello World Tutorial
In this tutorial you'll see how to generate the
most basic report: a simple "hello world!" textual report.
The first thing to learn is that every document
should begin with
beginDocument() and end with a call to
endDocument().
reportGenerator.beginDocument();
reportGenerator.endDocument();
A document must have a head, where some things are
declared (for example new colors, page margins, etc). For now, let's
just declare it without anything besides their normal behavior (it's
mandatory to every document have a head explicitly declared).
reportGenerator.beginDocument();
reportGenerator.beginDocumentHead();
reportGenerator.endDocumentHead();
reportGenerator.endDocument();
You are a clever person and are thinking: "if we
must have a document head, we probably must have a document body". And
I can say: "You are absolutely right!", all report elements that
will be visible in the report final format are inserted inside the
document's body. Thus, we must declare the body block.
reportGenerator.beginDocument();
reportGenerator.beginDocumentHead();
reportGenerator.endDocumentHead();
reportGenerator.beginDocumentBody();
reportGenerator.endDocumentBody();
reportGenerator.endDocument();
"And if we have a body, the text to be visible
should be inside that", you are thinking. Gosh, right again! is this
tutorial really necessary?
reportGenerator.beginDocument();
reportGenerator.beginDocumentHead();
reportGenerator.endDocumentHead();
reportGenerator.beginDocumentBody();
reportGenerator.addText("Hello world!");
reportGenerator.endDocumentBody();
reportGenerator.endDocument();
Here's the pdf generated by NervalReports' PDFReportGenerator:
And
here you can download the full code of this tutorial.