This class provides methods for generating PCL print files.
changePrintDirection
public void changePrintDirection(int rotate)
throws IOException
Changes the current print direction while maintaining the current cursor position.
rotate
- the rotation angle (counterclockwise), one of 0, 90, 180 and 270.
clearHorizontalMargins
public void clearHorizontalMargins()
throws IOException
Clears the horizontal margins.
convertToGray
public final int convertToGray(int r,
int g,
int b)
Convert an RGB color value to a grayscale from 0 to 100.
r
- the red componentg
- the green componentb
- the blue component
convertToPCLShade
public final int convertToPCLShade(Color col)
Convert a Color value to a PCL shade value (0-100).
- the PCL shade value (100=black)
defineGrayscalePattern
public void defineGrayscalePattern(Color col,
int patternID,
int ditherMatrixSize)
throws IOException
Generates a user-defined pattern for a dithering pattern matching the grayscale value
of the color given.
col
- the color to create the pattern forpatternID
- the pattern ID to useditherMatrixSize
- the size of the Bayer dither matrix to use (4 or 8 supported)
enterHPGL2Mode
public void enterHPGL2Mode(boolean restorePreviousHPGL2Cursor)
throws IOException
Enters the HP GL/2 mode.
restorePreviousHPGL2Cursor
- true if the previous HP GL/2 pen position should be
restored, false if the current position is maintained
enterPCLMode
public void enterPCLMode(boolean restorePreviousPCLCursor)
throws IOException
Enters the PCL mode.
restorePreviousPCLCursor
- true if the previous PCL cursor position should be restored,
false if the current position is maintained
fillRect
protected void fillRect(int w,
int h,
Color col)
throws IOException
Generate a filled rectangle at the current cursor position.
w
- the width in millipointsh
- the height in millipointscol
- the fill color
formFeed
public void formFeed()
throws IOException
Sends the form feed character.
formatDouble2
public final String formatDouble2(double value)
Formats a double value with two decimal positions for PCL output.
formatDouble4
public final String formatDouble4(double value)
Formats a double value with four decimal positions for PCL output.
getMaximumBitmapResolution
public int getMaximumBitmapResolution()
- the maximum resolution to encode bitmap images at
getOutputStream
public OutputStream getOutputStream()
- the OutputStream that this generator writes to
isGrayscaleImage
public static boolean isGrayscaleImage(RenderedImage img)
Indicates whether an image is a grayscale image.
- true if it's a grayscale image
isMonochromeImage
public static boolean isMonochromeImage(RenderedImage img)
Indicates whether an image is a monochrome (b/w) image.
- true if it's a monochrome image
paintBitmap
public void paintBitmap(RenderedImage img,
Dimension targetDim,
boolean sourceTransparency)
throws IOException
Paint a bitmap at the current cursor position. The bitmap is converted to a monochrome
(1-bit) bitmap image.
img
- the bitmap imagetargetDim
- the target Dimention (in mpt)sourceTransparency
- true if the background should not be erased
paintMonochromeBitmap
public void paintMonochromeBitmap(RenderedImage img,
int resolution)
throws IOException
Paint a bitmap at the current cursor position. The bitmap must be a monochrome
(1-bit) bitmap image.
img
- the bitmap image (must be 1-bit b/w)resolution
- the resolution of the image (must be a PCL resolution)
popCursorPos
public void popCursorPos()
throws IOException
Pops the current cursor position from the stack.
pushCursorPos
public void pushCursorPos()
throws IOException
Pushes the current cursor position on a stack (stack size: max 20 entries)
resetPrinter
public void resetPrinter()
throws IOException
Resets the printer and restores the user default environment.
selectCurrentPattern
public void selectCurrentPattern(int patternID,
int pattern)
throws IOException
Select the current pattern
patternID
- the pattern ID (*c#G command)pattern
- the pattern type (*v#T command)
selectGrayscale
public void selectGrayscale(Color col)
throws IOException
Selects the current grayscale color (the given color is converted to grayscales).
selectPageSize
public void selectPageSize(int selector)
throws IOException
Selects the page size.
selector
- the integer representing the page size
selectPaperSource
public void selectPaperSource(int selector)
throws IOException
Selects the paper source. The parameter is usually printer-specific. Usually, "1" is the
default tray, "2" is the manual paper feed, "3" is the manual envelope feed, "4" is the
"lower" tray and "7" is "auto-select". Consult the technical reference for your printer
for all available values.
selector
- the integer representing the paper source/tray
separateJobs
public void separateJobs()
throws IOException
Sends the job separation command.
setCursorPos
public void setCursorPos(double x,
double y)
throws IOException
Sets the cursor to a new absolute coordinate.
x
- the X coordinate (in millipoints)y
- the Y coordinate (in millipoints)
setPatternTransparencyMode
public void setPatternTransparencyMode(boolean transparent)
throws IOException
Sets the pattern transparency mode.
transparent
- true if transparent, false for opaque
setRasterGraphicsResolution
public void setRasterGraphicsResolution(int value)
throws IOException
Sets the raster graphics resolution
value
- the resolution value (units per inch)
setSourceTransparencyMode
public void setSourceTransparencyMode(boolean transparent)
throws IOException
Sets the source transparency mode.
transparent
- true if transparent, false for opaque
setTextLength
public void setTextLength(int numberOfLines)
throws IOException
The Text Length command can be used to define the bottom border. See the PCL specification
for details.
numberOfLines
- the number of lines
setTopMargin
public void setTopMargin(int numberOfLines)
throws IOException
The Top Margin command designates the number of lines between
the top of the logical page and the top of the text area.
numberOfLines
- the number of lines (See PCL specification for details)
setTransparencyMode
public void setTransparencyMode(boolean source,
boolean pattern)
throws IOException
Sets the transparency modes.
source
- source transparency: true if transparent, false for opaquepattern
- pattern transparency: true if transparent, false for opaque
setUnitOfMeasure
public void setUnitOfMeasure(int value)
throws IOException
Sets the unit of measure.
value
- the resolution value (units per inch)
setVMI
public void setVMI(double value)
throws IOException
Sets the Vertical Motion Index (VMI).
universalEndOfLanguage
public void universalEndOfLanguage()
throws IOException
Sends the universal end of language command (UEL).
writeCommand
public void writeCommand(String cmd)
throws IOException
Writes a PCL escape command to the output stream.
cmd
- the command (without the ESCAPE character)
writeText
public void writeText(String s)
throws IOException
Writes raw text (in ISO-8859-1 encoding) to the output stream.