Seam now includes an component set for generating documents using iText. The primary focus of Seam's iText document support is for the generation of PDF doucuments, but Seam also offers basic support for RTF document generation.
iText support is provided by jboss-seam-pdf.jar. This JAR contains the iText JSF controls, which are used to construct views that can render to PDF, and the DocumentStore component, which serves the rendered documents to the user. To include PDF support in your application, included jboss-seam-pdf.jar in your WEB-INF/lib directory along with the iText JAR file. There is no further configuration needed to use Seam's iText supportfon.
The Seam iText module requires the use of Facelets as the view technology. Future versions of the library may also support the use of JSP. Additionally, it requires the use of the seam-ui package.
The examples/itext project contains an example of the PDF support in action. It demonstrates proper deployment packaging, and it contains a number examples that demonstrate the key PDF generation features current supported.
<p:document> | Description Documents are generated by facelets documents using tags in the http://jboss.com/products/seam/pdf namespace. Documents should always have the document tag at the root of the document. The document tag prepares Seam to generate a document into the DocumentStore and renders an HTML redirect to that stored content. Attributes
Metadata Attributes
Usage <p:document xmlns:p="http://jboss.com/products/seam/pdf"> The document goes here. </p:document> |
Useful documents will need to contain more than just text; however, the standard UI components are geared towards HTML generation and are not useful for generating PDF content. Instead, Seam provides a special UI components for generating suitable PDF content. Tags like <p:image> and <p:paragraph> are the basic foundations of simple documents. Tags like <p:font> provide style information to all the content surrounging them.
<p:paragraph> | Description Most uses of text should be sectioned into paragraphs so that text fragments can be flowed, formatted and styled in logical groups. Attributes
Usage <p:paragraph alignment="justify"> This is a simple document. It isn't very fancy. </p:paragraph> |
<p:text> | Description The text tag allows text fragments to be produced from application data using normal JSF converter mechanisms. It is very similar to the outputText tag used when rendering HTML documents. Attributes
Usage <p:paragraph> The item costs <p:text value="#{product.price}"> <f:convertNumber type="currency" currencySymbol="$"/> </p:text> </p:paragraph> |
<p:font> | Description The font tag defines the default font to be used for all text inside of it. Attributes
Usage <p:font family="courier" style="bold" size="24"> <p:paragraph>My Title</p:paragraph> </p:font> |
<p:newPage> | Description p:newPage inserts a page break. Usage <p:newPage /> |
<p:image> | Description p:image inserts an image into the document. Images can be be loaded from the classpath or from the web application context using the value attribute. Resources can also be dynamically generated by application code. The imageData attribute can specify a value binding expression whose value is a java.awt.Image object. Attributes
Usage <p:image value="/jboss.jpg" /> <p:image value="#{images.chart}" /> |
<p:anchor> | Description p:anchor defines clickable links from a document. It supports the following attributes: Attributes
Usage <p:listItem><p:anchor reference="#reason1">Reason 1</p:anchor></p:listItem> ... <p:paragraph> <p:anchor name="reason1">It's the quickest way to get "rich"</p:anchor> ... </p:paragraph> |
<p:header> <p:footer> | Description The p:header and p:footer components provide the ability to place header and footer text on each page of a generated document, with the exception of the first page. Header and footer declarations should appear near the top of a document. Attributes
Usage <p:facet name="header"> <p:font size="12"> <p:footer borderWidthTop="1" borderColorTop="blue" borderWidthBottom="0" alignment="center"> Why Seam? [<p:pageNumber />] </p:footer> </p:font> </f:facet> |
<p:pageNumber> | Description The current page number can be placed inside of a header or footer using the p:pageNumber tag. The page number tag can only be used in the context of a header or footer and can only be used once. Usage <p:footer borderWidthTop="1" borderColorTop="blue" borderWidthBottom="0" alignment="center"> Why Seam? [<p:pageNumber />] </p:footer> |
<p:chapter> <p:section> | Description If the generated document follows a book/article structure, the p:chapter and p:section tags can be used to provide the necessary structure. Sections can only be used inside of chapters, but they may be nested arbitrarily deep. Most PDF viewers provide easy navigation between chapters and sections in a document. Attributes
Usage <p:document xmlns:p="http://jboss.com/products/seam/pdf" title="Hello"> <p:chapter number="1"> <p:title><p:paragraph>Hello</p:paragraph></p:title> <p:paragraph>Hello #{user.name}!</p:paragraph> </p:chapter> <p:chapter number="2"> <p:title><p:paragraph>Goodbye</p:paragraph></p:title> <p:paragraph>Goodbye #{user.name}.</p:paragraph> </p:chapter> </p:document> |
<p:header> | Description Any chapter or section can contain a p:title. The title will be displayed next to the chapter/section number. The body of the title may contain raw text or may be a p:paragraph. |
List structures can be displayed using the p:list and p:listItem tags. Lists may contain arbitrarily-nested sublists. List items may not be used outside of a list. he following document uses the ui:repeat tag to to display a list of values retrieved from a Seam component.
<p:document xmlns:p="http://jboss.com/products/seam/pdf" xmlns:ui="http://java.sun.com/jsf/facelets" title="Hello"> <p:list style="numbered"> <ui:repeat value="#{documents}" var="doc"> <p:listItem>#{doc.name}</p:listItem> </ui:repeat> </p:list> </p:document>
<p:list> | Attributes
Usage <p:list style="numbered"> <ui:repeat value="#{documents}" var="doc"> <p:listItem>#{doc.name}</p:listItem> </ui:repeat> </p:list> |
<p:listItem> | Description p:listItem supports the following attributes: Attributes
Usage ... |
Table structures can be created using the p:table and p:cell tags. Unlike many table structures, there is no explicit row declaration. If a table has 3 columns, then every 3 cells will automatically form a row. Header and footer rows can be declared, and the headers and footers will be repeated in the event a table structure spans multiple pages.
<p:table> | Description p:table supports the following attributes. Attributes
Usage <p:table columns="3" headerRows="1"> <p:cell>name</p:cell> <p:cell>owner</p:cell> <p:cell>size</p:cell> <ui:repeat value="#{documents}" var="doc"> <p:cell>#{doc.name}</p:cell> <p:cell>#{doc.user.name}</p:cell> <p:cell>#{doc.size}</p:cell> </ui:repeat> </p:table> |
<p:cell> | Description p:cell supports the following attributes. Attributes
Usage <p:cell>...</p:cell> |
This section documents some of the constants shared by attributes on multiple tags.
Seam documents do not yet support a full color specification. Currently, only named colors are supported. They are: white, gray, lightgray, darkgray, black, red, pink, yellow, green, magenta, cyan and blue.
Document generation works out of the box with no additional configuration needed. However, there are a few points of configuration that are needed for more serious applications.
The default implementation serves PDF documents from a generic URL, /seam-doc.seam. Many browsers (and users) would prefer to see URLs that contain the actual PDF name like /myDocument.pdf. This capability requires some configuration. To serve PDF files, all *.pdf resources should be mapped to the Seam Servlet Filter and to the DocumentStoreServlet:
<filter> <filter-name>Seam Servlet Filter</filter-name> <filter-class>org.jboss.seam.servlet.SeamServletFilter</filter-class> </filter> <filter-mapping> <filter-name>Seam Servlet Filter</filter-name> <url-pattern>*.pdf</url-pattern> </filter-mapping> <servlet> <servlet-name>Document Store Servlet</servlet-name> <servlet-class>org.jboss.seam.pdf.DocumentStoreServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>Document Store Servlet</servlet-name> <url-pattern>*.pdf</url-pattern> </servlet-mapping>
The useExtensions option on the document store component completes the functionality by instructing the document store to generate URLs with the correct filename extension for the document type being generated.
<components xmlns="http://jboss.com/products/seam/components" xmlns:pdf="http://jboss.com/products/seam/pdf"> <pdf:documentStore useExtensions="true" /> </components>
Generated documents are stored in conversation scope and will expire when the conversation ends. At that point, references to the document will be invalid. To You can specify a default view to be shown when a document does not exist using the errorPage property of the documentStore.
<pdf:documentStore useExtensions="true" errorPage="/pdfMissing.seam" />
<p:barchart> | Description Displays a bar chart. Attributes
Usage <p:barchart title="Bar Chart" legend="true" width="500" height="500"> <p:series key="Last Year"> <p:data columnKey="Joe" value="100" /> <p:data columnKey="Bob" value="120" /> </p:series> <p:series key="This Year"> <p:data columnKey="Joe" value="125" /> <p:data columnKey="Bob" value="115" /> </p:series> </p:barchart> |
<p:linechart> | Description Displays a line chart. Attributes
Usage <p:linechart title="Line Chart" width="500" height="500"> <p:series key="Prices"> <p:data columnKey="2003" value="7.36" /> <p:data columnKey="2004" value="11.50" /> <p:data columnKey="2005" value="34.625" /> <p:data columnKey="2006" value="76.30" /> <p:data columnKey="2007" value="85.05" /> </p:series> </p:linechart> |
<p:piechart> | Description Displays a pie chart. Attributes
Usage |
<p:series> | Description Category data can be broken down into series. The series tag is used to categorize a set of data with a series and apply styling to the entire series. Attributes
Usage <p:series key="data1"> <ui:repeat value="#{data.pieData1}" var="item"> <p:data columnKey="#{item.name}" value="#{item.value}" /> </ui:repeat> </p:series> |
<p:data> | Description The data tag describes each data point to be displayed in the graph. Attributes
Usage <p:data key="foo" value="20" sectionPaint="#111111" explodedPercent=".2" /> <p:data key="bar" value="30" sectionPaint="#333333" /> <p:data key="baz" value="40" sectionPaint="#555555" sectionOutlineStroke="my-dot-style" /> |
<p:color> | Description The color component declares a color or gradient than can be referenced when drawing filled shapes. Attributes
Usage <p:color id="foo" color="#0ff00f"/> <p:color id="bar" color="#ff00ff" color2="#00ff00" point="50 50" point2="300 300"/> |
<p:stroke> | Description Describes a stroke used to draw lines in a chart. Attributes
Usage <p:stroke id="dot2" width="2" cap="round" join="bevel" dash="2 3" /> |
...