com.jrefinery.report.targets.pageable.output
Class PDFOutputTarget

java.lang.Object
  |
  +--com.jrefinery.report.targets.pageable.output.AbstractOutputTarget
        |
        +--com.jrefinery.report.targets.pageable.output.PDFOutputTarget
All Implemented Interfaces:
LayoutSupport, OutputTarget

public class PDFOutputTarget
extends AbstractOutputTarget

An output target for the report engine that generates a PDF file using the iText class library (see http://www.lowagie.com/iText, note that the URL is case-sensitive!).

If the system property "com.jrefinery.report.targets.pageable.output.PDFOutputTarget.AUTOINIT" is set to "true", the PDF-FontFactory is automatically initialized when this class is loaded. Be aware that embedding many fonts will result in larger files.

When using Unicode characters, you will have to adjust the encoding of this target to "Identity-H", to enable horizontal unicode printing. This will result in larger files.

The Encoding property is now a string with one of the values of "none" "40bit" or "128bit".

Author:
David Gilbert, Thomas Morgner

Field Summary
static java.lang.String CONFIGURATION_PREFIX
          The configuration prefix.
static java.lang.String EMBED_FONTS
          Literal text for the 'EmbedFonts' property name.
static java.lang.String ENCODING
          The encoding key.
static java.lang.String SECURITY_ALLOW_ASSEMBLY
          Literal text for the 'AllowAssembly' property name.
static java.lang.String SECURITY_ALLOW_COPY
          Literal text for the 'AllowCopy' property name.
static java.lang.String SECURITY_ALLOW_DEGRADED_PRINTING
          Literal text for the 'AllowDegradedPrinting' property name.
static java.lang.String SECURITY_ALLOW_FILLIN
          Literal text for the 'AllowFillIn' property name.
static java.lang.String SECURITY_ALLOW_MODIFY_ANNOTATIONS
          Literal text for the 'AllowModifyAnnotations' property name.
static java.lang.String SECURITY_ALLOW_MODIFY_CONTENTS
          Literal text for the 'AllowModifyContents' property name.
static java.lang.String SECURITY_ALLOW_PRINTING
          Literal text for the 'AllowPrinting' property name.
static java.lang.String SECURITY_ALLOW_SCREENREADERS
          Literal text for the 'AllowScreenReaders' property name.
static java.lang.String SECURITY_ENCRYPTION
          Literal text for the 'Encryption' property name.
static java.lang.String SECURITY_ENCRYPTION_128BIT
          A constant for the encryption type (128 bit).
static java.lang.String SECURITY_ENCRYPTION_40BIT
          A constant for the encryption type (40 bit).
static java.lang.String SECURITY_ENCRYPTION_NONE
          A constant for the encryption type (40 bit).
static java.lang.String SECURITY_OWNERPASSWORD
          Literal text for the 'ownerpassword' property name.
static java.lang.String SECURITY_USERPASSWORD
          Literal text for the 'userpassword' property name.
 
Fields inherited from interface com.jrefinery.report.targets.pageable.OutputTarget
AUTHOR, TITLE
 
Constructor Summary
PDFOutputTarget(java.io.OutputStream out, LogicalPage logPage, boolean embedFonts)
          Creates a new PDFOutputTarget.
PDFOutputTarget(java.io.OutputStream out, java.awt.print.PageFormat pageFormat, boolean embedFonts)
          Constructs a PDFOutputTarget.
PDFOutputTarget(java.io.OutputStream out, java.awt.print.PageFormat logPageFormat, java.awt.print.PageFormat physPageFormat, boolean embedFonts)
          Creates a new PDFOutputTarget.
 
Method Summary
 void beginPage(PhysicalPage format)
          Signals that a page is being started.
 void close()
          Closes the document.
 void configure(ReportConfiguration config)
          Configures the output target.
 OutputTarget createDummyWriter()
          Creates an output target that mimics a real output target, but produces no output.
 SizeCalculator createTextSizeCalculator(FontDefinition font)
          Creates a 'size calculator' for the current state of the output target.
 void drawDrawable(DrawableContainer drawable)
          Draws a drawable relative to the current position.
 void drawImage(ImageReference imageRef)
          Draws an image from this ImageReference.
 void drawShape(java.awt.Shape shape)
          Draws a shape at the specified location.
 void drawString(java.lang.String text)
          Draws the band onto the specified graphics device.
 void endPage()
          This method is called when the page is ended.
 void fillShape(java.awt.Shape shape)
          Draws a shape at the specified location.
 com.lowagie.text.pdf.BaseFont getBaseFont()
          Returns the iText BaseFont.
 FontDefinition getFont()
          Returns the currently active AWT-Font.
 java.awt.Paint getPaint()
          Returns the currently set paint.
 java.awt.Stroke getStroke()
          Returns the current stroke.
 boolean isOpen()
          Returns true if the output target is open, and false otherwise.
 void open()
          Opens the document.
 void setFont(FontDefinition font)
          Sets the current font.
 void setFontEncoding(java.lang.String encoding)
          Defines the text encoding used in this output target.
 void setOperationBounds(java.awt.geom.Rectangle2D bounds)
          Sets the operation bounds.
 void setPaint(java.awt.Paint paint)
          Sets the paint.
 void setStroke(java.awt.Stroke stroke)
          Defines the stroke used to draw shapes.
 
Methods inherited from class com.jrefinery.report.targets.pageable.output.AbstractOutputTarget
createContentFactory, getContentFactory, getHorizontalAlignmentBorder, getLogicalPage, getOperationBounds, getProperty, getProperty, getPropertyNames, getVerticalAlignmentBorder, setProperty
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONFIGURATION_PREFIX

public static final java.lang.String CONFIGURATION_PREFIX
The configuration prefix.

See Also:
Constant Field Values

EMBED_FONTS

public static final java.lang.String EMBED_FONTS
Literal text for the 'EmbedFonts' property name.

See Also:
Constant Field Values

SECURITY_ALLOW_PRINTING

public static final java.lang.String SECURITY_ALLOW_PRINTING
Literal text for the 'AllowPrinting' property name.

See Also:
Constant Field Values

SECURITY_ALLOW_MODIFY_CONTENTS

public static final java.lang.String SECURITY_ALLOW_MODIFY_CONTENTS
Literal text for the 'AllowModifyContents' property name.

See Also:
Constant Field Values

SECURITY_ALLOW_COPY

public static final java.lang.String SECURITY_ALLOW_COPY
Literal text for the 'AllowCopy' property name.

See Also:
Constant Field Values

SECURITY_ALLOW_MODIFY_ANNOTATIONS

public static final java.lang.String SECURITY_ALLOW_MODIFY_ANNOTATIONS
Literal text for the 'AllowModifyAnnotations' property name.

See Also:
Constant Field Values

SECURITY_ALLOW_FILLIN

public static final java.lang.String SECURITY_ALLOW_FILLIN
Literal text for the 'AllowFillIn' property name.

See Also:
Constant Field Values

SECURITY_ALLOW_SCREENREADERS

public static final java.lang.String SECURITY_ALLOW_SCREENREADERS
Literal text for the 'AllowScreenReaders' property name.

See Also:
Constant Field Values

SECURITY_ALLOW_ASSEMBLY

public static final java.lang.String SECURITY_ALLOW_ASSEMBLY
Literal text for the 'AllowAssembly' property name.

See Also:
Constant Field Values

SECURITY_ALLOW_DEGRADED_PRINTING

public static final java.lang.String SECURITY_ALLOW_DEGRADED_PRINTING
Literal text for the 'AllowDegradedPrinting' property name.

See Also:
Constant Field Values

SECURITY_ENCRYPTION

public static final java.lang.String SECURITY_ENCRYPTION
Literal text for the 'Encryption' property name.

See Also:
Constant Field Values

SECURITY_ENCRYPTION_NONE

public static final java.lang.String SECURITY_ENCRYPTION_NONE
A constant for the encryption type (40 bit).

See Also:
Constant Field Values

SECURITY_ENCRYPTION_40BIT

public static final java.lang.String SECURITY_ENCRYPTION_40BIT
A constant for the encryption type (40 bit).

See Also:
Constant Field Values

SECURITY_ENCRYPTION_128BIT

public static final java.lang.String SECURITY_ENCRYPTION_128BIT
A constant for the encryption type (128 bit).

See Also:
Constant Field Values

SECURITY_USERPASSWORD

public static final java.lang.String SECURITY_USERPASSWORD
Literal text for the 'userpassword' property name.

See Also:
Constant Field Values

SECURITY_OWNERPASSWORD

public static final java.lang.String SECURITY_OWNERPASSWORD
Literal text for the 'ownerpassword' property name.

See Also:
Constant Field Values

ENCODING

public static final java.lang.String ENCODING
The encoding key.

See Also:
Constant Field Values
Constructor Detail

PDFOutputTarget

public PDFOutputTarget(java.io.OutputStream out,
                       java.awt.print.PageFormat pageFormat,
                       boolean embedFonts)
Constructs a PDFOutputTarget.

Parameters:
out - the output stream.
pageFormat - the page format.
embedFonts - embed fonts?

PDFOutputTarget

public PDFOutputTarget(java.io.OutputStream out,
                       LogicalPage logPage,
                       boolean embedFonts)
Creates a new PDFOutputTarget.

Parameters:
out - the output stream.
logPage - the logical page.
embedFonts - embed the fonts?

PDFOutputTarget

public PDFOutputTarget(java.io.OutputStream out,
                       java.awt.print.PageFormat logPageFormat,
                       java.awt.print.PageFormat physPageFormat,
                       boolean embedFonts)
Creates a new PDFOutputTarget.

Parameters:
out - the output stream.
logPageFormat - the logical page format.
physPageFormat - the physical page format.
embedFonts - embed the fonts?
Method Detail

getFont

public FontDefinition getFont()
Returns the currently active AWT-Font.

Returns:
the current font.

getBaseFont

public com.lowagie.text.pdf.BaseFont getBaseFont()
Returns the iText BaseFont.

Returns:
the iText BaseFont.

setFont

public void setFont(FontDefinition font)
             throws OutputTargetException
Sets the current font. The font is mapped to pdf specific fonts if possible. If no basefont could be created, an OutputTargetException is thrown.

Parameters:
font - the new font (null not permitted).
Throws:
OutputTargetException - if there was a problem setting the font for the target.

drawImage

public void drawImage(ImageReference imageRef)
               throws OutputTargetException
Draws an image from this ImageReference. The image is directly embedded into the pdf file to provide the best scaling support.

Parameters:
imageRef - the image reference.
Throws:
OutputTargetException - if there was a problem drawing the image to the target.

drawShape

public void drawShape(java.awt.Shape shape)
Draws a shape at the specified location. The shape is drawn using a PathIterator. All Shapes are supported. Set a stroke and a paint before drawing. The shape is not filled.

Parameters:
shape - the shape to draw.

fillShape

public void fillShape(java.awt.Shape shape)
Draws a shape at the specified location. The shape is drawn using a PathIterator. All Shapes are supported. Set a stroke and a paint before drawing. The shape is filled using the current paint and no outline is drawn.

Parameters:
shape - the shape to fill.

endPage

public void endPage()
             throws OutputTargetException
This method is called when the page is ended.

Throws:
OutputTargetException - if there was a problem with the target.

open

public void open()
          throws OutputTargetException
Opens the document.

Throws:
OutputTargetException - if there is a problem with the target.

beginPage

public void beginPage(PhysicalPage format)
Signals that a page is being started. Stores the state of the target to make it possible to restore the complete outputtarget.

Parameters:
format - the physical page.

close

public void close()
Closes the document.


drawString

public void drawString(java.lang.String text)
Draws the band onto the specified graphics device. The Text is printed on the bottom of the elements bounds.

Parameters:
text - The text to be printed.

setStroke

public void setStroke(java.awt.Stroke stroke)
               throws OutputTargetException
Defines the stroke used to draw shapes. If the stroke is of an invalid type, an OutputTargetException is thrown. Currently only BasicStroke is supported.

Parameters:
stroke - the stroke.
Throws:
OutputTargetException - if there is a problem with the target.

getStroke

public java.awt.Stroke getStroke()
Returns the current stroke.

Returns:
the current stroke.

setPaint

public void setPaint(java.awt.Paint paint)
              throws OutputTargetException
Sets the paint. If the paint could not be converted into a pdf object, an OutputTargetException is thrown. This implementation currently supports java.awt.Color as the only valid paint.

Parameters:
paint - the paint.
Throws:
OutputTargetException - if the paint is invalid.

getPaint

public java.awt.Paint getPaint()
Returns the currently set paint.

Returns:
the paint.

setFontEncoding

public void setFontEncoding(java.lang.String encoding)
Defines the text encoding used in this output target.

Parameters:
encoding - the font encoding.

createDummyWriter

public OutputTarget createDummyWriter()
Creates an output target that mimics a real output target, but produces no output. This is used by the reporting engine when it makes its first pass through the report, calculating page boundaries etc. The second pass will use a real output target.

Returns:
a dummy output target.

configure

public void configure(ReportConfiguration config)
Configures the output target.

Parameters:
config - the configuration.

isOpen

public boolean isOpen()
Returns true if the output target is open, and false otherwise.

Returns:
true or false.

createTextSizeCalculator

public SizeCalculator createTextSizeCalculator(FontDefinition font)
                                        throws OutputTargetException
Creates a 'size calculator' for the current state of the output target. The calculator is used to calculate the string width and line height and later maybe more.

Parameters:
font - the font.
Returns:
the size calculator.
Throws:
OutputTargetException - if there is a problem with the output target.

setOperationBounds

public void setOperationBounds(java.awt.geom.Rectangle2D bounds)
Sets the operation bounds.

Specified by:
setOperationBounds in interface OutputTarget
Overrides:
setOperationBounds in class AbstractOutputTarget
Parameters:
bounds - the bounds.

drawDrawable

public void drawDrawable(DrawableContainer drawable)
Draws a drawable relative to the current position.

Parameters:
drawable - the drawable to draw.