com.crionics.jpdf.creator
Class JPdfScreenshotPrinter

java.lang.Object
  extended by com.crionics.jpdf.creator.JPdfScreenshotPrinter
All Implemented Interfaces:
java.awt.print.Printable

public final class JPdfScreenshotPrinter
extends java.lang.Object
implements java.awt.print.Printable

A simple utility class that lets you do screen dumps of Java2D components without the need to write a specific print method.

The object can be called using two different methods:
1. A static call
JPdfScreenshotPrinter.printComponent(myJPanel);

2. Using an instance
JPdfScreenshotPrinter printer=new JPdfScreenshotPrinter(myJPanel);
print.print();

This second method gives more control as it allows to skip the print preview panel by passing the desired pageformat as a parameter

// Print on a Letter Portrait, skip print preview panel
print.print(new PageFormat());


Field Summary
static int CLIP_ON_PAGES
          Clips oversized components on several pages
static int FIT_PAGE
          Fits the component on a single page
static int FIT_PAGE_HEIGHT
          Resizes the component to the page height
static int FIT_PAGE_WIDTH
          Resizes the component to the page width
 
Fields inherited from interface java.awt.print.Printable
NO_SUCH_PAGE, PAGE_EXISTS
 
Constructor Summary
JPdfScreenshotPrinter()
          Creates a screenshot printer object.
JPdfScreenshotPrinter(java.io.File destination)
          Creates a screenshot printer object.
 
Method Summary
 int getFitPreferences()
          gets the clipping preferences
 java.awt.print.PageFormat getPageFormat()
           
 int print(java.awt.Graphics g, java.awt.print.PageFormat pageFormat1, int pageIndex)
          Should not be called directly, used internally to render components on PDF pages
 void printComponent(java.awt.Component theComponent)
          A handy method to easily print a Component
 void printComponents(java.awt.Component[] theComponent)
           
 void setFitPreferences(int fitpref)
          Sets the clipping preferences
 void setPageFormat(java.awt.print.PageFormat format)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLIP_ON_PAGES

public static final int CLIP_ON_PAGES
Clips oversized components on several pages

See Also:
Constant Field Values

FIT_PAGE_HEIGHT

public static final int FIT_PAGE_HEIGHT
Resizes the component to the page height

See Also:
Constant Field Values

FIT_PAGE_WIDTH

public static final int FIT_PAGE_WIDTH
Resizes the component to the page width

See Also:
Constant Field Values

FIT_PAGE

public static final int FIT_PAGE
Fits the component on a single page

See Also:
Constant Field Values
Constructor Detail

JPdfScreenshotPrinter

public JPdfScreenshotPrinter()
Creates a screenshot printer object. The instance will show a print preview pane when printComponent() methods are called.


JPdfScreenshotPrinter

public JPdfScreenshotPrinter(java.io.File destination)
Creates a screenshot printer object. The instance will NOT show a print preview pane.

Method Detail

getFitPreferences

public int getFitPreferences()
gets the clipping preferences

Returns:
one of FIT_PAGE, CLIP_ON_PAGES, FIT_PAGE_HEIGHT, FIT_PAGE_WIDTH

getPageFormat

public java.awt.print.PageFormat getPageFormat()

print

public int print(java.awt.Graphics g,
                 java.awt.print.PageFormat pageFormat1,
                 int pageIndex)
Should not be called directly, used internally to render components on PDF pages

Specified by:
print in interface java.awt.print.Printable

printComponent

public void printComponent(java.awt.Component theComponent)
                    throws PdfException
A handy method to easily print a Component

Parameters:
theComponent - the Component to be printed
Throws:
PdfException

printComponents

public void printComponents(java.awt.Component[] theComponent)
                     throws PdfException
Throws:
PdfException

setFitPreferences

public void setFitPreferences(int fitpref)
Sets the clipping preferences

Parameters:
fitpref - one of FIT_PAGE, CLIP_ON_PAGES, FIT_PAGE_HEIGHT, FIT_PAGE_WIDTH

setPageFormat

public void setPageFormat(java.awt.print.PageFormat format)


Copyright © 1999-2007 Crionics. All Rights Reserved.