public class PCLGenerator extends Object
| Modifier and Type | Field and Description |
|---|---|
static char |
ESC
The ESC (escape) character
|
protected Map<PCLSoftFontManager,Map<Typeface,Long>> |
fontManagerMap |
protected Map<Typeface,PCLFontReader> |
fontReaderMap |
static int[] |
PCL_RESOLUTIONS
A list of all supported resolutions in PCL (values in dpi)
|
| Constructor and Description |
|---|
PCLGenerator(OutputStream out)
Main constructor.
|
PCLGenerator(OutputStream out,
int maxResolution)
Main constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addFont(PCLSoftFontManager sfManager,
Typeface font) |
void |
changePrintDirection(int rotate)
Changes the current print direction while maintaining the current cursor position.
|
void |
clearHorizontalMargins()
Clears the horizontal margins.
|
int |
convertToGray(int r,
int g,
int b)
Convert an RGB color value to a grayscale from 0 to 100.
|
int |
convertToPCLShade(Color col)
Convert a Color value to a PCL shade value (0-100).
|
void |
defineGrayscalePattern(Color col,
int patternID,
int ditherMatrixSize)
Generates a user-defined pattern for a dithering pattern matching the grayscale value
of the color given.
|
void |
enterHPGL2Mode(boolean restorePreviousHPGL2Cursor)
Enters the HP GL/2 mode.
|
void |
enterPCLMode(boolean restorePreviousPCLCursor)
Enters the PCL mode.
|
protected void |
fillRect(int w,
int h,
Color col,
boolean colorEnabled)
Generate a filled rectangle at the current cursor position.
|
String |
formatDouble2(double value)
Formats a double value with two decimal positions for PCL output.
|
String |
formatDouble4(double value)
Formats a double value with four decimal positions for PCL output.
|
void |
formFeed()
Sends the form feed character.
|
float |
getDitheringQuality()
Returns the dithering quality used when encoding gray or color images.
|
int |
getMaximumBitmapResolution() |
OutputStream |
getOutputStream() |
String |
getTextEncoding()
Returns the currently active text encoding.
|
static boolean |
isGrayscaleImage(RenderedImage img)
Indicates whether an image is a grayscale image.
|
static boolean |
isJAIAvailable()
Indicates whether JAI is available.
|
static boolean |
isMonochromeImage(RenderedImage img)
Indicates whether an image is a monochrome (b/w) image.
|
void |
paintBitmap(RenderedImage img,
Dimension targetDim,
boolean sourceTransparency,
PCLRenderingUtil pclUtil)
Paint a bitmap at the current cursor position.
|
void |
paintMonochromeBitmap(RenderedImage img,
int resolution)
Paint a bitmap at the current cursor position.
|
void |
popCursorPos()
Pops the current cursor position from the stack.
|
void |
pushCursorPos()
Pushes the current cursor position on a stack (stack size: max 20 entries)
|
void |
resetPrinter()
Resets the printer and restores the user default environment.
|
void |
selectColor(Color col) |
void |
selectCurrentPattern(int patternID,
int pattern)
Select the current pattern
|
void |
selectDuplexMode(int selector)
Selects the duplexing mode for the page.
|
void |
selectGrayscale(Color col)
Selects the current grayscale color (the given color is converted to grayscales).
|
void |
selectOutputBin(int selector)
Selects the output bin.
|
void |
selectPageSize(int selector)
Selects the page size.
|
void |
selectPaperSource(int selector)
Selects the paper source.
|
void |
separateJobs()
Sends the job separation command.
|
void |
setCursorPos(double x,
double y)
Sets the cursor to a new absolute coordinate.
|
void |
setDitheringQuality(float quality)
Sets the dithering quality used when encoding gray or color images.
|
void |
setPatternTransparencyMode(boolean transparent)
Sets the pattern transparency mode.
|
void |
setRasterGraphicsResolution(int value)
Sets the raster graphics resolution
|
void |
setSourceTransparencyMode(boolean transparent)
Sets the source transparency mode.
|
void |
setTextLength(int numberOfLines)
The Text Length command can be used to define the bottom border.
|
void |
setTopMargin(int numberOfLines)
The Top Margin command designates the number of lines between
the top of the logical page and the top of the text area.
|
void |
setTransparencyMode(boolean source,
boolean pattern)
Sets the transparency modes.
|
void |
setUnitOfMeasure(int value)
Sets the unit of measure.
|
void |
setVMI(double value)
Sets the Vertical Motion Index (VMI).
|
void |
universalEndOfLanguage()
Sends the universal end of language command (UEL).
|
void |
writeBytes(byte[] bytes)
Writes raw bytes to the output stream
|
void |
writeCommand(String cmd)
Writes a PCL escape command to the output stream.
|
void |
writeText(String s)
Writes raw text (in ISO-8859-1 encoding) to the output stream.
|
public static final char ESC
public static final int[] PCL_RESOLUTIONS
protected Map<Typeface,PCLFontReader> fontReaderMap
protected Map<PCLSoftFontManager,Map<Typeface,Long>> fontManagerMap
public PCLGenerator(OutputStream out)
out - the OutputStream to write the PCL stream topublic PCLGenerator(OutputStream out, int maxResolution)
out - the OutputStream to write the PCL stream tomaxResolution - the maximum resolution to encode bitmap images atpublic void addFont(PCLSoftFontManager sfManager, Typeface font)
public OutputStream getOutputStream()
public String getTextEncoding()
public int getMaximumBitmapResolution()
public void writeCommand(String cmd) throws IOException
cmd - the command (without the ESCAPE character)IOException - In case of an I/O errorpublic void writeText(String s) throws IOException
s - the textIOException - In case of an I/O errorpublic void writeBytes(byte[] bytes)
throws IOException
bytes - The bytesIOException - In case of an I/O errorpublic final String formatDouble2(double value)
value - value to formatpublic final String formatDouble4(double value)
value - value to formatpublic void universalEndOfLanguage()
throws IOException
IOException - In case of an I/O errorpublic void resetPrinter()
throws IOException
IOException - In case of an I/O errorpublic void separateJobs()
throws IOException
IOException - In case of an I/O errorpublic void formFeed()
throws IOException
IOException - In case of an I/O errorpublic void setUnitOfMeasure(int value)
throws IOException
value - the resolution value (units per inch)IOException - In case of an I/O errorpublic void setRasterGraphicsResolution(int value)
throws IOException
value - the resolution value (units per inch)IOException - In case of an I/O errorpublic void selectPageSize(int selector)
throws IOException
selector - the integer representing the page sizeIOException - In case of an I/O errorpublic void selectPaperSource(int selector)
throws IOException
selector - the integer representing the paper source/trayIOException - In case of an I/O errorpublic void selectOutputBin(int selector)
throws IOException
selector - the integer representing the output binIOException - In case of an I/O errorpublic void selectDuplexMode(int selector)
throws IOException
selector - the integer representing the duplexing mode of the pageIOException - In case of an I/O errorpublic void clearHorizontalMargins()
throws IOException
IOException - In case of an I/O errorpublic void setTopMargin(int numberOfLines)
throws IOException
numberOfLines - the number of lines (See PCL specification for details)IOException - In case of an I/O errorpublic void setTextLength(int numberOfLines)
throws IOException
numberOfLines - the number of linesIOException - In case of an I/O errorpublic void setVMI(double value)
throws IOException
value - the VMI valueIOException - In case of an I/O errorpublic void setCursorPos(double x,
double y)
throws IOException
x - the X coordinate (in millipoints)y - the Y coordinate (in millipoints)IOException - In case of an I/O errorpublic void pushCursorPos()
throws IOException
IOException - In case of an I/O errorpublic void popCursorPos()
throws IOException
IOException - In case of an I/O errorpublic void changePrintDirection(int rotate)
throws IOException
rotate - the rotation angle (counterclockwise), one of 0, 90, 180 and 270.IOException - In case of an I/O errorpublic void enterHPGL2Mode(boolean restorePreviousHPGL2Cursor)
throws IOException
restorePreviousHPGL2Cursor - true if the previous HP GL/2 pen position should be
restored, false if the current position is maintainedIOException - In case of an I/O errorpublic void enterPCLMode(boolean restorePreviousPCLCursor)
throws IOException
restorePreviousPCLCursor - true if the previous PCL cursor position should be restored,
false if the current position is maintainedIOException - In case of an I/O errorprotected void fillRect(int w,
int h,
Color col,
boolean colorEnabled)
throws IOException
w - the width in millipointsh - the height in millipointscol - the fill colorIOException - In case of an I/O errorpublic void defineGrayscalePattern(Color col, int patternID, int ditherMatrixSize) throws IOException
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)IOException - In case of an I/O errorpublic void setSourceTransparencyMode(boolean transparent)
throws IOException
transparent - true if transparent, false for opaqueIOException - In case of an I/O errorpublic void setPatternTransparencyMode(boolean transparent)
throws IOException
transparent - true if transparent, false for opaqueIOException - In case of an I/O errorpublic void setTransparencyMode(boolean source,
boolean pattern)
throws IOException
source - source transparency: true if transparent, false for opaquepattern - pattern transparency: true if transparent, false for opaqueIOException - In case of an I/O errorpublic final int convertToGray(int r,
int g,
int b)
r - the red componentg - the green componentb - the blue componentpublic final int convertToPCLShade(Color col)
col - the colorpublic void selectGrayscale(Color col) throws IOException
col - the colorIOException - In case of an I/O errorpublic void selectColor(Color col) throws IOException
IOExceptionpublic void selectCurrentPattern(int patternID,
int pattern)
throws IOException
patternID - the pattern ID (<ESC>*c#G command)pattern - the pattern type (<ESC>*v#T command)IOException - In case of an I/O errorpublic void setDitheringQuality(float quality)
quality - a quality setting between 0.0f (worst/fastest) and 1.0f (best/slowest)public float getDitheringQuality()
public static boolean isMonochromeImage(RenderedImage img)
img - the imagepublic static boolean isGrayscaleImage(RenderedImage img)
img - the imagepublic static boolean isJAIAvailable()
public void paintBitmap(RenderedImage img, Dimension targetDim, boolean sourceTransparency, PCLRenderingUtil pclUtil) throws IOException
img - the bitmap imagetargetDim - the target Dimention (in mpt)sourceTransparency - true if the background should not be erasedIOException - In case of an I/O errorpublic void paintMonochromeBitmap(RenderedImage img, int resolution) throws IOException
img - the bitmap image (must be 1-bit b/w)resolution - the resolution of the image (must be a PCL resolution)IOException - In case of an I/O errorCopyright © 2023 Apache Software Foundation. All rights reserved.