Graphs, Flash, PDF Sets and Xinclude
A few new features were added to the Report Generator 1.1.51 - although it's largely a stable product these days, the following were just too useful to leave out.
Version 2 Graphs
The Report Generator embeds version 1 of our Graph Library, which is good enough for basic graphs. We have a few customers who need the additional power of our full Graph Library however, and integrating the two until now hasn't been as easy as it should have been.
That's all changed with 1.1.51 - provided the Graph Library's
bfograph.jar file is in your classpath, you can now embed the Graph XML tags directly into your
Report Generator XML. All you need to remember is to set the namespace on the graph
tags - here's a quick example:
<?xml version="1.0"?> <!DOCTYPE pdf PUBLIC "-//big.faceless.org/report" "report-1.1.dtd"> <pdf> <head> </head> <body> <p> Here's a version 2 graph - note the namespace. </p> <piegraph xmlns="http://bfo.co.uk/ns/graph?version=2" width="300" height="300"> <data key="s1" value="15" extend="10"> <label>Slice 1</label> </data> <data key="s2" value="70"> <label>Slice 2</label> </data> <data key="s3" value="20"> <label>Slice 3</label> </data> </piegraph> </body> </pdf>
Pretty simple really. If a font is included in the document via a "link" tag, it can
be referenced by name in the Graph Library as you'd expect, and the graphs are embedded
as vector images, for smaller files and higher quality printed output. Customers using
other approaches to embed graphs into their reports would almost certainly benefit
from switching to this approach. We've included a working example of this with the
Report Generator as
Flash in PDF? Yes, you've been able to do it since Acrobat 8, and we added support to our PDF Library in 2.11.14. This release adds support to the Report Generator, and the syntax is identical to HTML. Here's the result - you'll need to open this in Acrobat 8 or later, as embedded Flash objects are unlikely to be supported by other PDF viewers.
<?xml version="1.0"?> <!DOCTYPE pdf PUBLIC "-//big.faceless.org/report" "report-1.1.dtd"> <pdf> <body> <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="nervous" width="500" height="100"> <param name="movie" value=" http://kb2.adobe.com/cps/155/tn_15507/images/flashplayerversion.swf" /> </object> </body> </pdf>
The report generator can be pretty memory-hungry, particularly with large or complex documents. A useful hack that we've discussed elsewhere is to break the Report down into smaller chunks and concatenate them using the PDF Library. This is all very well, but it does mean getting away from the XML interface that makes the Report Generator so easy to use.
To help things along, we've added a way to concatenate several PDF documents into
on in XML. The new
<pdfset> element can be used to wrap one or more
<pdf> elements, and each PDF will be concatenated together to form the final document.
Here's a quick example that would create a two page document from two one-page documents.
<?xml version="1.0"?> <!DOCTYPE pdf PUBLIC "-//big.faceless.org/report" "report-1.1.dtd"> <pdfset> <pdf> <body> This text is in section 1 and will appear on page 1 </body> </pdf> <pdf> <body> This text is in section 2 and will appear on page 2 </body> </pdf> </pdfset>
This isn't very useful for a two page document, but splitting a 10,000 page document
into two 5,000 page documents and joining them with
<pdfset> should reduce the memory footprint when creating the report by a large amount.
Often the PDFs you want to concatenate are a combination of dynamic and existing,
for example to add a standard coversheet or disclaimer section to a report. The new
src attribute can be used on the
<pdf> tag inside a
<pdfset> to reference the PDF file to include. Here's how:
<?xml version="1.0"?> <!DOCTYPE pdf PUBLIC "-//big.faceless.org/report" "report-1.1.dtd"> <pdfset> <pdf> <body> This text is in section 1 and will appear on page 1 </body> </pdf> <pdf src="path/to/disclaimer.pdf" /> </pdfset>
<pdfset> will make life easier for our customers dealing with massive reports. There's an
example included with the Report Generator as
examples/samples/pdfset.xml, and there's more information on the new element in our Tag and Attribute Reference
The final new feature we're going to cover is also for those creating large documents.
Xinclude, a W3C standard way to embed one XML file inside another. This makes it easier to manage large documents,
and it's a perfect match for the
<pdfset> described above. Here's a quick example showing how you could concatenate two PDFs
in this way:
<?xml version="1.0"?> <!DOCTYPE pdf PUBLIC "-//big.faceless.org/report" "report-1.1.dtd"> <pdfset xmlns:xi="http://www.w3.org/2003/XInclude"> <xi:include href="pdf1.xml" /> <xi:include href="pdf2.xml" /> </pdfset>
pdf2.xml are files which use the standard Report Generator syntax to define a PDF in the regular