org.apache.batik.transcoder.print
Class PrintTranscoder

java.lang.Object
  extended byorg.apache.batik.transcoder.TranscoderSupport
      extended byorg.apache.batik.transcoder.AbstractTranscoder
          extended byorg.apache.batik.transcoder.XMLAbstractTranscoder
              extended byorg.apache.batik.transcoder.SVGAbstractTranscoder
                  extended byorg.apache.batik.transcoder.print.PrintTranscoder
All Implemented Interfaces:
Printable, Transcoder

public class PrintTranscoder
extends SVGAbstractTranscoder
implements Printable

This class is a Transcoder that prints SVG images. This class works as follows: any-time the transcode method is invoked, the corresponding input is cached and nothing else happens.
However, the PrintTranscoder is also a Printable. If used in a print operation, it will print each of the input it cached, one input per page.
The PrintTranscoder uses several different hints that guide its printing:


Nested Class Summary
 
Nested classes inherited from class org.apache.batik.transcoder.SVGAbstractTranscoder
SVGAbstractTranscoder.SVGAbstractTranscoderUserAgent
 
Field Summary
static String KEY_AOI_STR
           
static String KEY_HEIGHT_STR
           
static String KEY_LANGUAGE_STR
           
static TranscodingHints.Key KEY_MARGIN_BOTTOM
          The marginBottom key.
static String KEY_MARGIN_BOTTOM_STR
           
static TranscodingHints.Key KEY_MARGIN_LEFT
          The marginLeft key.
static String KEY_MARGIN_LEFT_STR
           
static TranscodingHints.Key KEY_MARGIN_RIGHT
          The marginRight key.
static String KEY_MARGIN_RIGHT_STR
           
static TranscodingHints.Key KEY_MARGIN_TOP
          The marginTop key.
static String KEY_MARGIN_TOP_STR
           
static TranscodingHints.Key KEY_PAGE_HEIGHT
          The pageHeight key.
static String KEY_PAGE_HEIGHT_STR
           
static TranscodingHints.Key KEY_PAGE_ORIENTATION
          The pageOrientation key.
static String KEY_PAGE_ORIENTATION_STR
           
static TranscodingHints.Key KEY_PAGE_WIDTH
          The pageWidth key.
static String KEY_PAGE_WIDTH_STR
           
static String KEY_PIXEL_TO_MM_STR
           
static TranscodingHints.Key KEY_SCALE_TO_PAGE
          The scaleToPage key.
static String KEY_SCALE_TO_PAGE_STR
           
static TranscodingHints.Key KEY_SHOW_PAGE_DIALOG
          The showPageDialog key.
static String KEY_SHOW_PAGE_DIALOG_STR
           
static TranscodingHints.Key KEY_SHOW_PRINTER_DIALOG
          The showPrinterDialog key.
static String KEY_SHOW_PRINTER_DIALOG_STR
           
static String KEY_USER_STYLESHEET_URI_STR
           
static String KEY_WIDTH_STR
           
static String KEY_XML_PARSER_CLASSNAME_STR
           
static String USAGE
           
static String VALUE_MEDIA_PRINT
           
static String VALUE_PAGE_ORIENTATION_LANDSCAPE
           
static String VALUE_PAGE_ORIENTATION_PORTRAIT
           
static String VALUE_PAGE_ORIENTATION_REVERSE_LANDSCAPE
           
 
Fields inherited from class org.apache.batik.transcoder.SVGAbstractTranscoder
builder, ctx, curAOI, curTxf, DEFAULT_ALLOWED_SCRIPT_TYPES, DEFAULT_DEFAULT_FONT_FAMILY, height, KEY_ALLOWED_SCRIPT_TYPES, KEY_ALTERNATE_STYLESHEET, KEY_AOI, KEY_CONSTRAIN_SCRIPT_ORIGIN, KEY_DEFAULT_FONT_FAMILY, KEY_EXECUTE_ONLOAD, KEY_HEIGHT, KEY_LANGUAGE, KEY_MAX_HEIGHT, KEY_MAX_WIDTH, KEY_MEDIA, KEY_PIXEL_TO_MM, KEY_PIXEL_UNIT_TO_MILLIMETER, KEY_SNAPSHOT_TIME, KEY_USER_STYLESHEET_URI, KEY_WIDTH, root, userAgent, width
 
Fields inherited from class org.apache.batik.transcoder.XMLAbstractTranscoder
KEY_DOCUMENT_ELEMENT, KEY_DOCUMENT_ELEMENT_NAMESPACE_URI, KEY_DOM_IMPLEMENTATION, KEY_XML_PARSER_CLASSNAME, KEY_XML_PARSER_VALIDATING
 
Fields inherited from class org.apache.batik.transcoder.TranscoderSupport
handler, hints
 
Fields inherited from interface java.awt.print.Printable
NO_SUCH_PAGE, PAGE_EXISTS
 
Constructor Summary
PrintTranscoder()
          Constructs a new transcoder that prints images.
 
Method Summary
static void handleValueError(String property, String value)
           
static void main(String[] args)
           
 void print()
          Convenience method
 int print(Graphics _g, PageFormat pageFormat, int pageIndex)
          Printable implementation
protected  void setImageSize(float docWidth, float docHeight)
          Sets document size according to the hints.
static void setTranscoderBooleanHint(Transcoder transcoder, String property, TranscodingHints.Key key)
           
static void setTranscoderFloatHint(Transcoder transcoder, String property, TranscodingHints.Key key)
           
static void setTranscoderRectangleHint(Transcoder transcoder, String property, TranscodingHints.Key key)
           
static void setTranscoderStringHint(Transcoder transcoder, String property, TranscodingHints.Key key)
           
protected  void transcode(Document document, String uri, TranscoderOutput output)
          Transcodes the specified Document as an image in the specified output.
 void transcode(TranscoderInput in, TranscoderOutput out)
          Transcodes the specified XML input in the specified output.
 
Methods inherited from class org.apache.batik.transcoder.SVGAbstractTranscoder
createBridgeContext, createBridgeContext, createBridgeContext, createDocumentFactory, createUserAgent, getCanvasGraphicsNode
 
Methods inherited from class org.apache.batik.transcoder.TranscoderSupport
addTranscodingHint, getErrorHandler, getTranscodingHints, removeTranscodingHint, setErrorHandler, setTranscodingHints, setTranscodingHints
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.batik.transcoder.Transcoder
addTranscodingHint, getErrorHandler, getTranscodingHints, removeTranscodingHint, setErrorHandler, setTranscodingHints, setTranscodingHints
 

Field Detail

KEY_AOI_STR

public static final String KEY_AOI_STR
See Also:
Constant Field Values

KEY_HEIGHT_STR

public static final String KEY_HEIGHT_STR
See Also:
Constant Field Values

KEY_LANGUAGE_STR

public static final String KEY_LANGUAGE_STR
See Also:
Constant Field Values

KEY_MARGIN_BOTTOM_STR

public static final String KEY_MARGIN_BOTTOM_STR
See Also:
Constant Field Values

KEY_MARGIN_LEFT_STR

public static final String KEY_MARGIN_LEFT_STR
See Also:
Constant Field Values

KEY_MARGIN_RIGHT_STR

public static final String KEY_MARGIN_RIGHT_STR
See Also:
Constant Field Values

KEY_MARGIN_TOP_STR

public static final String KEY_MARGIN_TOP_STR
See Also:
Constant Field Values

KEY_PAGE_HEIGHT_STR

public static final String KEY_PAGE_HEIGHT_STR
See Also:
Constant Field Values

KEY_PAGE_ORIENTATION_STR

public static final String KEY_PAGE_ORIENTATION_STR
See Also:
Constant Field Values

KEY_PAGE_WIDTH_STR

public static final String KEY_PAGE_WIDTH_STR
See Also:
Constant Field Values

KEY_PIXEL_TO_MM_STR

public static final String KEY_PIXEL_TO_MM_STR
See Also:
Constant Field Values

KEY_SCALE_TO_PAGE_STR

public static final String KEY_SCALE_TO_PAGE_STR
See Also:
Constant Field Values

KEY_SHOW_PAGE_DIALOG_STR

public static final String KEY_SHOW_PAGE_DIALOG_STR
See Also:
Constant Field Values

KEY_SHOW_PRINTER_DIALOG_STR

public static final String KEY_SHOW_PRINTER_DIALOG_STR
See Also:
Constant Field Values

KEY_USER_STYLESHEET_URI_STR

public static final String KEY_USER_STYLESHEET_URI_STR
See Also:
Constant Field Values

KEY_WIDTH_STR

public static final String KEY_WIDTH_STR
See Also:
Constant Field Values

KEY_XML_PARSER_CLASSNAME_STR

public static final String KEY_XML_PARSER_CLASSNAME_STR
See Also:
Constant Field Values

VALUE_MEDIA_PRINT

public static final String VALUE_MEDIA_PRINT
See Also:
Constant Field Values

VALUE_PAGE_ORIENTATION_LANDSCAPE

public static final String VALUE_PAGE_ORIENTATION_LANDSCAPE
See Also:
Constant Field Values

VALUE_PAGE_ORIENTATION_PORTRAIT

public static final String VALUE_PAGE_ORIENTATION_PORTRAIT
See Also:
Constant Field Values

VALUE_PAGE_ORIENTATION_REVERSE_LANDSCAPE

public static final String VALUE_PAGE_ORIENTATION_REVERSE_LANDSCAPE
See Also:
Constant Field Values

KEY_SHOW_PAGE_DIALOG

public static final TranscodingHints.Key KEY_SHOW_PAGE_DIALOG
The showPageDialog key.

Key:

KEY_SHOW_PAGE_DIALOG

Value:

Boolean

Default:

false

Required:

No

Description:

Specifies whether or not the transcoder should pop up a dialog box for selecting the page format.


KEY_SHOW_PRINTER_DIALOG

public static final TranscodingHints.Key KEY_SHOW_PRINTER_DIALOG
The showPrinterDialog key.

Key:

KEY_SHOW_PAGE_DIALOG

Value:

Boolean

Default:

false

Required:

No

Description:

Specifies whether or not the transcoder should pop up a dialog box for selecting the printer. If the dialog box is not shown, the transcoder will use the default printer.


KEY_PAGE_WIDTH

public static final TranscodingHints.Key KEY_PAGE_WIDTH
The pageWidth key.

Key:

KEY_PAGE_WIDTH

Value:

Length

Default:

None

Required:

No

Description:

The width of the print page


KEY_PAGE_HEIGHT

public static final TranscodingHints.Key KEY_PAGE_HEIGHT
The pageHeight key.

Key:

KEY_PAGE_HEIGHT

Value:

Length

Default:

None

Required:

No

Description:

The height of the print page


KEY_MARGIN_TOP

public static final TranscodingHints.Key KEY_MARGIN_TOP
The marginTop key.

Key:

KEY_MARGIN_TOP

Value:

Length

Default:

None

Required:

No

Description:

The print page top margin


KEY_MARGIN_RIGHT

public static final TranscodingHints.Key KEY_MARGIN_RIGHT
The marginRight key.

Key:

KEY_MARGIN_RIGHT

Value:

Length

Default:

None

Required:

No

Description:

The print page right margin


KEY_MARGIN_BOTTOM

public static final TranscodingHints.Key KEY_MARGIN_BOTTOM
The marginBottom key.

Key:

KEY_MARGIN_BOTTOM

Value:

Length

Default:

None

Required:

No

Description:

The print page bottom margin


KEY_MARGIN_LEFT

public static final TranscodingHints.Key KEY_MARGIN_LEFT
The marginLeft key.

Key:

KEY_MARGIN_LEFT

Value:

Length

Default:

None

Required:

No

Description:

The print page left margin


KEY_PAGE_ORIENTATION

public static final TranscodingHints.Key KEY_PAGE_ORIENTATION
The pageOrientation key.

Key:

KEY_PAGE_ORIENTATION

Value:

String

Default:

VALUE_PAGE_ORIENTATION_PORTRAIT

Required:

No

Description:

The print page's orientation


KEY_SCALE_TO_PAGE

public static final TranscodingHints.Key KEY_SCALE_TO_PAGE
The scaleToPage key.

Key:

KEY_SCALE_TO_PAGE

Value:

Boolean

Default:

true

Required:

No

Description:

Specifies whether or not the SVG images are scaled to fit into the printed page


USAGE

public static final String USAGE
See Also:
Constant Field Values
Constructor Detail

PrintTranscoder

public PrintTranscoder()
Constructs a new transcoder that prints images.

Method Detail

transcode

public void transcode(TranscoderInput in,
                      TranscoderOutput out)
Description copied from class: XMLAbstractTranscoder
Transcodes the specified XML input in the specified output. All TranscoderException exceptions not catched previously are tagged as fatal errors (ie. call the fatalError method of the ErrorHandler).

Specified by:
transcode in interface Transcoder
Overrides:
transcode in class SVGAbstractTranscoder

transcode

protected void transcode(Document document,
                         String uri,
                         TranscoderOutput output)
                  throws TranscoderException
Transcodes the specified Document as an image in the specified output.

Overrides:
transcode in class SVGAbstractTranscoder
Parameters:
document - the document to transcode
uri - the uri of the document or null if any
output - the ouput where to transcode
Throws:
TranscoderException - if an error occured while transcoding

print

public void print()
           throws PrinterException
Convenience method

Throws:
PrinterException

print

public int print(Graphics _g,
                 PageFormat pageFormat,
                 int pageIndex)
Printable implementation

Specified by:
print in interface Printable

setImageSize

protected void setImageSize(float docWidth,
                            float docHeight)
Sets document size according to the hints. Global variables width and height are modified.

Overrides:
setImageSize in class SVGAbstractTranscoder
Parameters:
docWidth - Width of the document.
docHeight - Height of the document.

main

public static void main(String[] args)
                 throws Exception
Throws:
Exception

setTranscoderFloatHint

public static void setTranscoderFloatHint(Transcoder transcoder,
                                          String property,
                                          TranscodingHints.Key key)

setTranscoderRectangleHint

public static void setTranscoderRectangleHint(Transcoder transcoder,
                                              String property,
                                              TranscodingHints.Key key)

setTranscoderBooleanHint

public static void setTranscoderBooleanHint(Transcoder transcoder,
                                            String property,
                                            TranscodingHints.Key key)

setTranscoderStringHint

public static void setTranscoderStringHint(Transcoder transcoder,
                                           String property,
                                           TranscodingHints.Key key)

handleValueError

public static void handleValueError(String property,
                                    String value)


Copyright © 2009 Apache Software Foundation. All Rights Reserved.