Configuring the Application to Use a PDF View
The last part of the setup involves simply telling Spring that you want to use your PDF genera-
tor class as the View. In views.properties(shown following in Listing 8-40) we simply set the
home page Viewclass to the one we just coded.
Listing 8-40.views.properties Entries for the PDF Home Page
homepage.class=com.apress.expertspringmvc.flight.web.view.HomePagePdf
Now when our home page is accessed, the PDF is generated on the fly, and your browser
will either ask you what to do with the file or simply open your PDF viewer and display the
results. Figure 8-8 shows the PDF.
Figure 8-8.The home page rendered as a PDF
Template PDFs with FOP
Creating anything other than trivial PDFs on the fly with iText is likely to be very time-consuming
and code intensive, as can be seen from the preceding examples. You might like to investigate the
Apache Formatting Objects Processor (FOP) driver, which can create the PDF from a template.
An example of how to get started is in the Spring sandbox, which contains an
AbstractXslFoViewclass. The sandbox is available as part of the Spring source code available
from the SourceForge project site (http://sourceforge.net/projects/springframework). You
will also have to download the FOP library, which is large, from http://xmlgraphics.apache.
org/fop.
■NoteThe AbstractXslFoViewis actually an extension of Spring’s XSLT support rather than its PDF sup-
port. The basic technology is XSLT, and PDF simply happens to be the output format from the transformation.
CHAPTER 8 ■SUPPORTED VIEW TYPES 257