Seam render pdf




















After all, what good would it be? Seam can render raw file data in addition to static files read from the classpath and input streams, in any of the following ways:. The Seam UI component set includes an enhanced graphic component capable of operating on a dynamically generated image. This value is used to serve a static graphic resource from the web application context e.

Table You should recognize that one of the supported Java types listed in table The image data is specified in the value attribute. In this example, we display image data retrieved from the database. However, you can also use a Seam component to create an image using Java 2D. The image can be prepared in a Seam component, converted to one of the accepted Java types listed in table But before you venture into Java 2D, you may be able to leverage one of the basic image transformations that Seam provides.

Each component tag accepts one or more parameters that control how the transformation is applied. These transformations are the same as those provided by the Image class from the Seam API introduced in section But it may be necessary to scale it even further to create a thumbnail for personalizing a review or comment that the golfer posts somewhere on the site, as shown here:.

You can easily create your own transformation component by implementing the interface org. This interface has one method, applyTransform , which accepts the Image type from the Seam API that you worked with in section Well, with Seam, the answer to this question is plenty.

You see, Seam goes well beyond just playing matchmaker between the browser and the PDF renderer. To enable PDF support in your application, you need to add two files to the application classpath: itext. You can then begin using the PDF component tags in your Facelets templates. You can use Facelets and Seam composition tags e. Notice that nowhere in that description did I mention Java. In this scenario, we want to avoid the use of Java to reuse our Facelets knowledge to create dynamic views.

For the most part, the PDF component tags map one to one with the functionality provided by iText. An iText PDF document rendered through Seam consists of paragraphs, images, headers, footers, chapters, sections, tables, lists, bar codes, and even Swing components.

You can customize the font size, font color, and background color on most elements. Some limitations exist, but the PDF component tags should be sufficient for all but the most complex requirements. Rather than itemize each and every tag in the PDF component palette, I provide a comprehensive example that puts many of the tags to use.

This approach will give you real-world experience with the PDF tags, which you can supplement by consulting the reference documentation for the specifics of each tag. In this example, we generate a scorecard in PDF format for a golf course.

The scorecard is the grid of holes and tee sets that you use to record the number of strokes you took on each hole. Thus, I guarantee that this will be a rewarding experience. The associations between these entities are configured to be lazy loaded.

For instance, rendering the scorecard would cause a large number of lazy associations to be crossed, in turn causing a lot of queries. To optimize, we want to use a page action to eagerly fetch all the necessary data in a single query and then make that data available to the Facelets template.

The Scorecard component, shown in listing The Scorecard component also provides a handful of utility methods needed to render portions of the scorecard. The use of the terms out and in represent the two halves of the golf course. Out is the first nine holes, leading away from the clubhouse. In is the back nine holes, returning to the clubhouse.

The methods getTeesOut and getTeesIn are invoked from the Facelets template using a parameterized value expression.

A scorecard is complex and so is the Facelets template needed to generate it. We get there in two phases. In the first phase, we get our feet wet with a simple PDF report. The first step is to create the Facelets template exportCourseInfo.

This template renders basic information about a course and the facility logo. Next, we connect a page action to this view ID to preload the scorecard data, defined in the exportCourseInfo. As you can see in listing If used alone, this tag will produce an empty document and push it to the browser. You can also change the orientation and size of the page. You can set the output format using the type attribute , which accepts three values: pdf , rtf , and html.

Here, the output format is controlled by the request parameter type , if present. Moving on to the content of the document, the template includes one image , three paragraphs , and one bulleted list.

It can read images from the Java types in table Expect this to be fixed in the future. In this case, we iterate over the tee sets on the course and display the tee set name and total distance in yards of each set as list items. The final result is shown in figure As you can see, creating a report in PDF format is no more difficult than creating a web page.

Most reports that you have to build probably require some sort of tabular data. We put these PDF table tags to the test by rendering a complete course scorecard, which shows the tee sets as well as the distances for each hole in a tee set. You explicitly state how many columns the table has by using the columns attribute.

To demonstrate the table component tag in action, we use it to help render the scorecard for a golf course. This use case offers enough complexity to show off many of the advanced capabilities of the table tag, rather than having me list them in a table.

Before jumping into the template, though, I briefly explain the goal. The first row displays the hole numbers. Following that row are rows for each tee set. The tee set rows consist of distance values that correspond with each hole number. The template that produces this markup, exportScorecard.

The default layout for a document is portrait, but the layout of this document is set to landscape to make room for the scorecard. If a table is wider than the document, the text in each cell is forced to wrap. The scorecard table has 22 columns and is configured to span the width of the page.

The first row is treated as a header, as defined by the headerRows attribute. This row is repeated if the table is divided across a page boundary. The widths attribute dictates the width ratios of the cells. In this example, the first column is three times as wide as the other columns in the table. Here we establish the default padding, wrap behavior, and alignments.

The final result of the scorecard is shown in figure The scorecard makes liberal use of color and grayscale shading. You can also apply colors to text, cell backgrounds, tables, sections, and image borders.

The scorecard example makes use of color for the header row text and most of the cell backgrounds. Given that you are working in a Facelets template, you need a translation layer. Fortunately, Seam provides one. Seam lets you choose from several color code sets that you can use to specify a color value in a component tag attribute. The possible value types you can enter are shown in table If you enter an invalid color value, an exception will be thrown when the document is rendered. The AWT color constant names are the most convenient approach and should be sufficient if basic colors will do.

There are some limitations with the template-based approach, but remember that if you find yourself pushing the envelope of what these tags can handle, you can always switch to using the iText API directly. We first look at customizing the document store servlet to handle missing documents and serve friendly file extensions, and then dig deeper into how to use it to serve your own documents.

The phase listener traps requests matching this path, reads the id from the request parameter, and pushes the document with this id to the browser. Notice the conversation token in the URL. The documentStore component is scoped to the conversation. Thus, documents exist for the lifetime of the conversation that created them. Then, configure the documentStore component as follows:.

There are two steps to making this change. First, add the org. DocumentStoreServlet to the web. Then let the document store component know that this servlet is available and can be used by adding the use-extensions attribute to the component configuration:. When extensions are enabled, Seam prepares the document URL by removing the default suffix from the view ID and replacing it with the file extension of the document.

A redirect is then issued to the new path. The filename in the path is completely irrelevant to Seam. The only piece of information that matters is the docId request parameter. For this reason, I highly recommend that you use the file extension feature.

I promised earlier that you would see other ways to serve a binary document. One option is to create a custom servlet. Creating a document. Attributes type — The type of the document to be produced. Basic Text Elements. Attributes firstLineIndent extraParagraphSpace leading multipliedLeading spacingBefore — The blank space to be inserted before the element.

Headers and Footers. Chapters and Sections. Note You cannot include a chapter into another chapter, this can be done only with section s. Note Chapter s can have a number or without it by setting numberDepth to 0. Attributes columns — The number of columns cells that make up a table row. If document has 2 rows which make up the header and one row that makes up the footer, headerRows should be set to 3 and footerRows should be set to 1 widthPercentage — The percentage of the page width that the table spans.

Document Constants. Color Values. Alignment Values. Attributes chart — The chart object to display. Default value is true is3D —A boolean value indicating that the chart should be rendered in 3D instead of 2D. Valid values are butt , round and square join — The line join type.

Valid values are miter , round and bevel miterLimit — For miter joins, this value is the limit of the size of the join.

Bar codes. Attributes type — A barcode type supported by iText. Attributes width — The width of the component to be rendered. Configuring iText. Description Most uses of text should be sectioned into paragraphs so that text fragments can be flowed, formatted and styled in logical groups. It isn't very fancy. Description The text tag allows text fragments to be produced from application data using normal JSF converter mechanisms.

Attributes value — The value to be displayed. Attributes value — The text to be displayed. Description The font tag defines the default font to be used for all text inside of it. Description p:textcolumn inserts a text column that can be used to control the flow of text. Description p:newPage inserts a page break. Description p:image inserts an image into the document. Attributes value — A resource name or a method expression binding to an application-generated image.

Description p:anchor defines clickable links from a document. It supports the following attributes: Attributes name — The name of an in-document anchor destination. Description The p:header and p:footer components provide the ability to place header and footer text on each page of a generated document.

Description The current page number can be placed inside of a header or footer using the p:pageNumber tag. Description Any chapter or section can contain a p:title. Description p:listItem supports the following attributes: Attributes alignment — The alignment of the list item. Description p:table supports the following attributes. Description p:cell supports the following attributes.

Attributes colspan — Cells can span more than one column by declaring a colspan greater than 1. Description Displays a chart created in Java by a Seam component. HTML single page. PDF 3. API Javadoc. PDF 4. PDF 2. You can not post a blank message. Please type your message and try again. This project is read only now. This content has been marked as final. Show 10 replies. Especially useful with Seam Mail. Is there any way to render the. I'm not sure, I've never tried, but try modifying the itext example to use your API call as a test: Renderer.

Renderer class and it's an abstract class: Name "org. What the hell is going on with this core dev team? What a disaster! To include PDF support in your application, put jboss-seam-pdf.



0コメント

  • 1000 / 1000