info.informatica.doc.pdf.itext
Class PDFStyleFormatter

java.lang.Object
  extended by info.informatica.doc.pdf.itext.PDFStyleFormatter

public class PDFStyleFormatter
extends Object

Utility class for helping in the format of iText PDF documents based on CSS style sheets.

TODO: work in progress.

Author:
Carlos Amengual (amengual at informatica.info)

Constructor Summary
PDFStyleFormatter(UserAgent<com.itextpdf.text.Image> userAgent)
           
 
Method Summary
 com.itextpdf.text.Chunk createChunk(CSSInlineBox box)
          Creates a chunk with the text and font specified by the given box.
 com.itextpdf.text.Chunk createChunk(CSSInlineBox box, String text)
          Creates a chunk with the text and font specified by the given box.
 com.itextpdf.text.Chunk createChunk(DownloadListener<com.itextpdf.text.Image> box)
          Creates a chunk with an image.
 com.itextpdf.text.Font createFont(CSS2ComputedProperties styledecl)
          Create an iText font from the properties specified in the given style.
 com.itextpdf.text.Phrase createPhrase(CSSInlineBox box)
          Creates a Phrase object according to the style of an inline box.
 void formatChunk(CSS2ComputedProperties styledecl, com.itextpdf.text.Chunk ch)
          Creates a chunk with the given text and the font specified by the style applying to the given box.
 void formatDocument(CSSBox box, com.itextpdf.text.Document pdf)
           
 void formatList(CSSContainerBox box, com.itextpdf.text.List list)
           
 void formatListItem(CSSContainerBox box, com.itextpdf.text.ListItem item)
           
 void formatParagraph(CSSBox box, com.itextpdf.text.Paragraph par)
          Formats the given paragraph according to the style that applies to the given peer element.
 void formatPCell(CSSTableCellBox box, com.itextpdf.text.pdf.PdfPCell cell)
          Formats a PdfPCell according to the style that applies to the given peer element.
 void formatPTable(CSSContainerBox box, com.itextpdf.text.pdf.PdfPTable table)
          Formats a PdfPTable according to the style that applies to the given peer element.
 void formatRectangle(CSSBox box, com.itextpdf.text.Rectangle rect)
           
 StyleDatabase getStyleDatabase()
          Gets the style database associated to this formatter.
protected  UserAgent<com.itextpdf.text.Image> getUserAgent()
           
static int translateAlignment(String align)
          Translates the alignment as provided by CSS/XHTML, to alignment as understood by the iText package.
static int translateVerticalAlignment(String align)
          Translates the vertical alignment as provided by CSS/XHTML, to same alignment as understood by the iText package.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PDFStyleFormatter

public PDFStyleFormatter(UserAgent<com.itextpdf.text.Image> userAgent)
Method Detail

getStyleDatabase

public StyleDatabase getStyleDatabase()
Gets the style database associated to this formatter.

Returns:
the style database.

getUserAgent

protected UserAgent<com.itextpdf.text.Image> getUserAgent()

createFont

public com.itextpdf.text.Font createFont(CSS2ComputedProperties styledecl)
                                  throws com.itextpdf.text.DocumentException
Create an iText font from the properties specified in the given style.

Parameters:
styledecl - the style declaration.
Returns:
the Font specified in the style sheet, or the closest one that could be created.
Throws:
com.itextpdf.text.DocumentException

translateAlignment

public static int translateAlignment(String align)
Translates the alignment as provided by CSS/XHTML, to alignment as understood by the iText package.

Parameters:
align - a string with the alignment identifier (left, right, center, justify).
Returns:
the alignment according to com.itextpdf.text.Element.

translateVerticalAlignment

public static int translateVerticalAlignment(String align)
Translates the vertical alignment as provided by CSS/XHTML, to same alignment as understood by the iText package.

Returns:
the vertical alignment according to com.itextpdf.text.Element.

createChunk

public com.itextpdf.text.Chunk createChunk(CSSInlineBox box)
Creates a chunk with the text and font specified by the given box.

Parameters:
box - the inline box.
Returns:
the chunk.

createChunk

public com.itextpdf.text.Chunk createChunk(CSSInlineBox box,
                                           String text)
Creates a chunk with the text and font specified by the given box.

Parameters:
box - the inline box.
Returns:
the chunk.

createChunk

public com.itextpdf.text.Chunk createChunk(DownloadListener<com.itextpdf.text.Image> box)
Creates a chunk with an image.

Parameters:
box - the box containing an image.
Returns:
the chunk.

formatChunk

public void formatChunk(CSS2ComputedProperties styledecl,
                        com.itextpdf.text.Chunk ch)
Creates a chunk with the given text and the font specified by the style applying to the given box.

Parameters:
styledecl - the style applying to the chunk box.
ch - the chunk to format.

createPhrase

public com.itextpdf.text.Phrase createPhrase(CSSInlineBox box)
Creates a Phrase object according to the style of an inline box.

Parameters:
box - the inline box.
Returns:
the phrase.

formatDocument

public void formatDocument(CSSBox box,
                           com.itextpdf.text.Document pdf)

formatRectangle

public void formatRectangle(CSSBox box,
                            com.itextpdf.text.Rectangle rect)

formatParagraph

public void formatParagraph(CSSBox box,
                            com.itextpdf.text.Paragraph par)
Formats the given paragraph according to the style that applies to the given peer element.

Parameters:
box - the box to be rendered.
par - the paragraph to be formatted.

formatPTable

public void formatPTable(CSSContainerBox box,
                         com.itextpdf.text.pdf.PdfPTable table)
Formats a PdfPTable according to the style that applies to the given peer element.

Parameters:
box - the box to be rendered.
table - the table to be formatted.

formatPCell

public void formatPCell(CSSTableCellBox box,
                        com.itextpdf.text.pdf.PdfPCell cell)
Formats a PdfPCell according to the style that applies to the given peer element.

Parameters:
box - the box to be rendered.
cell - the cell to be formatted.

formatList

public void formatList(CSSContainerBox box,
                       com.itextpdf.text.List list)

formatListItem

public void formatListItem(CSSContainerBox box,
                           com.itextpdf.text.ListItem item)


Copyright © 2011 informatica.info. All Rights Reserved.