Class PrintTranscoder
- java.lang.Object
-
- org.apache.batik.transcoder.TranscoderSupport
-
- org.apache.batik.transcoder.AbstractTranscoder
-
- org.apache.batik.transcoder.XMLAbstractTranscoder
-
- org.apache.batik.transcoder.SVGAbstractTranscoder
-
- org.apache.batik.transcoder.print.PrintTranscoder
-
- All Implemented Interfaces:
java.awt.print.Printable,Transcoder
public class PrintTranscoder extends SVGAbstractTranscoder implements java.awt.print.Printable
This class is aTranscoderthat 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, thePrintTranscoderis also a Printable. If used in a print operation, it will print each of the input it cached, one input per page.
ThePrintTranscoderuses several different hints that guide its printing:
KEY_LANGUAGE, KEY_USER_STYLESHEET_URI, KEY_PIXEL_TO_MM, KEY_XML_PARSER_CLASSNAMEcan be used to set the defaults for the various SVG properties.KEY_PAGE_WIDTH, KEY_PAGE_HEIGHT, KEY_MARGIN_TOP, KEY_MARGIN_BOTTOM, KEY_MARGIN_LEFT, KEY_MARGIN_RIGHTandKEY_PAGE_ORIENTATIONcan be used to specify the printing page characteristics.KEY_WIDTH, KEY_HEIGHTcan be used to specify how to scale the SVG imageKEY_SCALE_TO_PAGEcan be used to specify whether or not the SVG image should be scaled uniformly to fit into the printed page or if it should just be centered into the printed page.
- Version:
- $Id: PrintTranscoder.java 1808001 2017-09-11 09:51:29Z ssteiner $
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.batik.transcoder.SVGAbstractTranscoder
SVGAbstractTranscoder.SVGAbstractTranscoderUserAgent
-
-
Field Summary
Fields Modifier and Type Field Description private intcurIndexIndex of the page corresponding to rootprivate java.util.ListinputsSet of inputs this transcoder has been requested to transcode so far.static java.lang.StringKEY_AOI_STRstatic java.lang.StringKEY_HEIGHT_STRstatic java.lang.StringKEY_LANGUAGE_STRstatic TranscodingHints.KeyKEY_MARGIN_BOTTOMThe marginBottom key.static java.lang.StringKEY_MARGIN_BOTTOM_STRstatic TranscodingHints.KeyKEY_MARGIN_LEFTThe marginLeft key.static java.lang.StringKEY_MARGIN_LEFT_STRstatic TranscodingHints.KeyKEY_MARGIN_RIGHTThe marginRight key.static java.lang.StringKEY_MARGIN_RIGHT_STRstatic TranscodingHints.KeyKEY_MARGIN_TOPThe marginTop key.static java.lang.StringKEY_MARGIN_TOP_STRstatic TranscodingHints.KeyKEY_PAGE_HEIGHTThe pageHeight key.static java.lang.StringKEY_PAGE_HEIGHT_STRstatic TranscodingHints.KeyKEY_PAGE_ORIENTATIONThe pageOrientation key.static java.lang.StringKEY_PAGE_ORIENTATION_STRstatic TranscodingHints.KeyKEY_PAGE_WIDTHThe pageWidth key.static java.lang.StringKEY_PAGE_WIDTH_STRstatic java.lang.StringKEY_PIXEL_TO_MM_STRstatic TranscodingHints.KeyKEY_SCALE_TO_PAGEThe scaleToPage key.static java.lang.StringKEY_SCALE_TO_PAGE_STRstatic TranscodingHints.KeyKEY_SHOW_PAGE_DIALOGThe showPageDialog key.static java.lang.StringKEY_SHOW_PAGE_DIALOG_STRstatic TranscodingHints.KeyKEY_SHOW_PRINTER_DIALOGThe showPrinterDialog key.static java.lang.StringKEY_SHOW_PRINTER_DIALOG_STRstatic java.lang.StringKEY_USER_STYLESHEET_URI_STRstatic java.lang.StringKEY_WIDTH_STRstatic java.lang.StringKEY_XML_PARSER_CLASSNAME_STRprivate java.util.ListprintedInputsCurrently printing set of pages.private BridgeContexttheCtxPlace to cache BridgeContext so we can dispose of it when it is appropriate.static java.lang.StringUSAGEstatic java.lang.StringVALUE_MEDIA_PRINTstatic java.lang.StringVALUE_PAGE_ORIENTATION_LANDSCAPEstatic java.lang.StringVALUE_PAGE_ORIENTATION_PORTRAITstatic java.lang.StringVALUE_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_ALLOW_EXTERNAL_RESOURCES, 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
-
-
Constructor Summary
Constructors Constructor Description PrintTranscoder()Constructs a new transcoder that prints images.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private voiddrawError(java.awt.Graphics g, java.lang.Exception e)Prints an error on the output pagestatic voidhandleValueError(java.lang.String property, java.lang.String value)static voidmain(java.lang.String[] args)voidprint()Convenience methodintprint(java.awt.Graphics _g, java.awt.print.PageFormat pageFormat, int pageIndex)Printable implementationprotected voidsetImageSize(float docWidth, float docHeight)Sets document size according to the hints.static voidsetTranscoderBooleanHint(Transcoder transcoder, java.lang.String property, TranscodingHints.Key key)static voidsetTranscoderFloatHint(Transcoder transcoder, java.lang.String property, TranscodingHints.Key key)static voidsetTranscoderRectangleHint(Transcoder transcoder, java.lang.String property, TranscodingHints.Key key)static voidsetTranscoderStringHint(Transcoder transcoder, java.lang.String property, TranscodingHints.Key key)voidtranscode(TranscoderInput in, TranscoderOutput out)Transcodes the specified XML input in the specified output.protected voidtranscode(org.w3c.dom.Document document, java.lang.String uri, TranscoderOutput output)Transcodes the specified Document as an image 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 java.lang.String KEY_AOI_STR
- See Also:
- Constant Field Values
-
KEY_HEIGHT_STR
public static final java.lang.String KEY_HEIGHT_STR
- See Also:
- Constant Field Values
-
KEY_LANGUAGE_STR
public static final java.lang.String KEY_LANGUAGE_STR
- See Also:
- Constant Field Values
-
KEY_MARGIN_BOTTOM_STR
public static final java.lang.String KEY_MARGIN_BOTTOM_STR
- See Also:
- Constant Field Values
-
KEY_MARGIN_LEFT_STR
public static final java.lang.String KEY_MARGIN_LEFT_STR
- See Also:
- Constant Field Values
-
KEY_MARGIN_RIGHT_STR
public static final java.lang.String KEY_MARGIN_RIGHT_STR
- See Also:
- Constant Field Values
-
KEY_MARGIN_TOP_STR
public static final java.lang.String KEY_MARGIN_TOP_STR
- See Also:
- Constant Field Values
-
KEY_PAGE_HEIGHT_STR
public static final java.lang.String KEY_PAGE_HEIGHT_STR
- See Also:
- Constant Field Values
-
KEY_PAGE_ORIENTATION_STR
public static final java.lang.String KEY_PAGE_ORIENTATION_STR
- See Also:
- Constant Field Values
-
KEY_PAGE_WIDTH_STR
public static final java.lang.String KEY_PAGE_WIDTH_STR
- See Also:
- Constant Field Values
-
KEY_PIXEL_TO_MM_STR
public static final java.lang.String KEY_PIXEL_TO_MM_STR
- See Also:
- Constant Field Values
-
KEY_SCALE_TO_PAGE_STR
public static final java.lang.String KEY_SCALE_TO_PAGE_STR
- See Also:
- Constant Field Values
-
KEY_SHOW_PAGE_DIALOG_STR
public static final java.lang.String KEY_SHOW_PAGE_DIALOG_STR
- See Also:
- Constant Field Values
-
KEY_SHOW_PRINTER_DIALOG_STR
public static final java.lang.String KEY_SHOW_PRINTER_DIALOG_STR
- See Also:
- Constant Field Values
-
KEY_USER_STYLESHEET_URI_STR
public static final java.lang.String KEY_USER_STYLESHEET_URI_STR
- See Also:
- Constant Field Values
-
KEY_WIDTH_STR
public static final java.lang.String KEY_WIDTH_STR
- See Also:
- Constant Field Values
-
KEY_XML_PARSER_CLASSNAME_STR
public static final java.lang.String KEY_XML_PARSER_CLASSNAME_STR
- See Also:
- Constant Field Values
-
VALUE_MEDIA_PRINT
public static final java.lang.String VALUE_MEDIA_PRINT
- See Also:
- Constant Field Values
-
VALUE_PAGE_ORIENTATION_LANDSCAPE
public static final java.lang.String VALUE_PAGE_ORIENTATION_LANDSCAPE
- See Also:
- Constant Field Values
-
VALUE_PAGE_ORIENTATION_PORTRAIT
public static final java.lang.String VALUE_PAGE_ORIENTATION_PORTRAIT
- See Also:
- Constant Field Values
-
VALUE_PAGE_ORIENTATION_REVERSE_LANDSCAPE
public static final java.lang.String VALUE_PAGE_ORIENTATION_REVERSE_LANDSCAPE
- See Also:
- Constant Field Values
-
inputs
private java.util.List inputs
Set of inputs this transcoder has been requested to transcode so far. Purpose is not really clear: some data is added, and it is copied into printedInputs. But it is never read or cleared...
-
printedInputs
private java.util.List printedInputs
Currently printing set of pages. This vector is created as a clone of inputs when the first page is printed.
-
curIndex
private int curIndex
Index of the page corresponding to root
-
theCtx
private BridgeContext theCtx
Place to cache BridgeContext so we can dispose of it when it is appropriate. The Baseclass would dispose of it too soon.
-
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 java.lang.String USAGE
- See Also:
- Constant Field Values
-
-
Method Detail
-
transcode
public void transcode(TranscoderInput in, TranscoderOutput out)
Description copied from class:XMLAbstractTranscoderTranscodes the specified XML input in the specified output. AllTranscoderExceptionexceptions not catched previously are tagged as fatal errors (ie. call thefatalErrormethod of theErrorHandler).- Specified by:
transcodein interfaceTranscoder- Overrides:
transcodein classSVGAbstractTranscoder- Parameters:
in- the XML input to transcodeout- the ouput where to transcode
-
transcode
protected void transcode(org.w3c.dom.Document document, java.lang.String uri, TranscoderOutput output) throws TranscoderExceptionTranscodes the specified Document as an image in the specified output.- Overrides:
transcodein classSVGAbstractTranscoder- Parameters:
document- the document to transcodeuri- the uri of the document or null if anyoutput- the ouput where to transcode- Throws:
TranscoderException- if an error occured while transcoding
-
print
public void print() throws java.awt.print.PrinterExceptionConvenience method- Throws:
java.awt.print.PrinterException
-
print
public int print(java.awt.Graphics _g, java.awt.print.PageFormat pageFormat, int pageIndex)Printable implementation- Specified by:
printin interfacejava.awt.print.Printable
-
setImageSize
protected void setImageSize(float docWidth, float docHeight)Sets document size according to the hints. Global variables width and height are modified.- Overrides:
setImageSizein classSVGAbstractTranscoder- Parameters:
docWidth- Width of the document.docHeight- Height of the document.
-
drawError
private void drawError(java.awt.Graphics g, java.lang.Exception e)Prints an error on the output page
-
main
public static void main(java.lang.String[] args) throws java.lang.Exception- Throws:
java.lang.Exception
-
setTranscoderFloatHint
public static void setTranscoderFloatHint(Transcoder transcoder, java.lang.String property, TranscodingHints.Key key)
-
setTranscoderRectangleHint
public static void setTranscoderRectangleHint(Transcoder transcoder, java.lang.String property, TranscodingHints.Key key)
-
setTranscoderBooleanHint
public static void setTranscoderBooleanHint(Transcoder transcoder, java.lang.String property, TranscodingHints.Key key)
-
setTranscoderStringHint
public static void setTranscoderStringHint(Transcoder transcoder, java.lang.String property, TranscodingHints.Key key)
-
handleValueError
public static void handleValueError(java.lang.String property, java.lang.String value)
-
-