Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing a Color Box using PCL code

Status
Not open for further replies.

trawithya

Programmer
Oct 18, 2012
6
US
I am new to PCL coding and am running into some walls finding a way to print a simple colored box.

I am printing to HP Color LaserJet CP2025 printer using a text file to send directly to the printer.

I have figured out how to use the simple colors to print a basic green box, but my users would like to see a lime green or "bright" green box instead.

This is what I am currently using:
<esc>-12345x
<esc>*p000x000Y
<esc>*c1000A
<esc>*c300B
<esc>*r3U
<esc>*v2s
<esc>*c0P
<esc>-12345x

I am assuming I will need to use a more complex color set up and have been playing a with a few but without success. Any help in getting this box to print would be appreciated.

Thank you.
 
Assuming your printer DOES support PCL5 color try this ...

<esc>E
#Configure RGB, indexed by pixel, max 4 entries, 8 bits ea RGB value
<esc>*v6W 00 01 02 08 08 08 (those are 6 hex bytes followinw the W
#Define colors 0-2 (0=black,1=white,2=lime)
<esc>*v0a0b0c0I <esc>*v255a255b255c1I <esc>130a255b0c2I
#select lime color as defined in index 2
<esc>*v2S
#position cursor a print lime rectangle
<esc>*p500x500Y<esc>*c800a800b0P
Back to black
<esc>*v0S
#position cursor and print text
<esc>*p100x1500YBack to black
<esc>E

Get the PCL5c reference manual for a proper explanation
Don't include the comment lines beginning with a #
I hope I haven't made any typos. How you get the 6 hex bytes into
your file will depend on the capabilities of your editor.
I usually just enter some dummy bytes, and then go in using a
hex editor and change the dummies to the correct values.


Jim Asman
 
Just to correct a few errors in the original 'simple colour' sample; it should be:

Code:
<Esc>%-12345X     Universal Exit Language (UEL)
<Esc>*p000x       Cursor Position Horizontal (000 PCL units)
       000Y       Cursor Position Vertical   (000 PCL units)
<Esc>*c1000A      Rectangle Size Horizontal (1000 PCL units)
<Esc>*c300B       Rectangle Size Vertical   (300 PCL units)
<Esc>*r3U         Simple Colour: 3-Plane RGB Palette
<Esc>*v2S         Foreground Colour (index = 2)
<Esc>*c0P         Fill Rectangular Area: Solid Area
<Esc>%-12345X     Universal Exit Language (UEL)

where <Esc> represents the non-graphic control-code Escape character (decimal code 27, or hexadecimal 1B).
 
... and the 'palette colour' example is missing an '*v'; it should be (omitting the original comment lines):

Code:
<Esc>E            Printer Reset
<Esc>*v6W         Configure Image Data (data length = 6)
[ 6 bytes ]       [ 00 01 02 08 08 08 ]
<Esc>*v0a         Colour Component 1 (primary value = 0)
       0b         Colour Component 2 (primary value = 0)
       0c         Colour Component 3 (primary value = 0)
       0I         Assign Colour Index (index = 0)
<Esc>*v255a       Colour Component 1 (primary value = 255)
       255b       Colour Component 2 (primary value = 255)
       255c       Colour Component 3 (primary value = 255)
       1I         Assign Colour Index (index = 1)
<Esc>*v130a       Colour Component 1 (primary value = 130)
       255b       Colour Component 2 (primary value = 255)
       0c         Colour Component 3 (primary value = 0)
       2I         Assign Colour Index (index = 2)
<Esc>*v2S         Foreground Colour (index = 2)
<Esc>*p500x       Cursor Position Horizontal (500 PCL units)
       500Y       Cursor Position Vertical   (500 PCL units)
<Esc>*c800a       Rectangle Size Horizontal (800 PCL units)
       800b       Rectangle Size Vertical   (800 PCL units)
       0P         Fill Rectangular Area: Solid Area
<Esc>*v0S         Foreground Colour (index = 0)
<Esc>*p100x       Cursor Position Horizontal (100 PCL units)
       1500Y      Cursor Position Vertical   (1500 PCL units)
Back to black
<Esc>E            Printer Reset

By the way, I can't access the 'mkcolor.pcl' file (I get a 404 error).
 
Thank you for all the suggestions.

The process I am working with is creating a text file of PCL code that I send to the printer to print. I am still having difficulties with the line:

<Esc>*v6W Configure Image Data (data length = 6)
[ 6 bytes ] [ 00 01 02 08 08 08 ]

Are the bytes already in HEX or do I need to convert those numbers into their equivalent values? Is there a command to get it to read them as HEX?

 
... and here is an analysis of Jim's file:

Code:
<Esc>E            Printer Reset
<CR>              Carriage Return
<LF>              Line Feed
<Esc>(s3B         Primary Font: Stroke Weight: Bold
<CR>              Carriage Return
<LF>              Line Feed
<Esc>*p100x       Cursor Position Horizontal (100 PCL units)
       200Y       Cursor Position Vertical   (200 PCL units)
Some black text
<CR>              Carriage Return
<LF>              Line Feed
<Esc>*v6W         Configure Image Data (data length = 6)
[ 6 bytes ]       [ 00 01 02 08 08 08 ] <-- these are the binary values
<CR>              Carriage Return
<LF>              Line Feed
<Esc>*v0a         Colour Component 1 (primary value = 0)
       0b         Colour Component 2 (primary value = 0)
       0c         Colour Component 3 (primary value = 0)
       0I         Assign Colour Index (index = 0)
<Esc>*v255a       Colour Component 1 (primary value = 255)
       255b       Colour Component 2 (primary value = 255)
       255c       Colour Component 3 (primary value = 255)
       1I         Assign Colour Index (index = 1)
<Esc>*v130a       Colour Component 1 (primary value = 130)
       250b       Colour Component 2 (primary value = 250)
       0c         Colour Component 3 (primary value = 0)
       2I         Assign Colour Index (index = 2)
<CR>              Carriage Return
<LF>              Line Feed
<Esc>*v2S         Foreground Colour (index = 2)
<CR>              Carriage Return
<LF>              Line Feed
<Esc>*p500x       Cursor Position Horizontal (500 PCL units)
       500Y       Cursor Position Vertical   (500 PCL units)
<Esc>*c800a       Rectangle Size Horizontal (800 PCL units)
       800b       Rectangle Size Vertical   (800 PCL units)
       0P         Fill Rectangular Area: Solid Area
<CR>              Carriage Return
<LF>              Line Feed
<Esc>*v0S         Foreground Colour (index = 0)
<CR>              Carriage Return
<LF>              Line Feed
<Esc>*p188x       Cursor Position Horizontal (188 PCL units)
       1500Y      Cursor Position Vertical   (1500 PCL units)
Back to black
<CR>              Carriage Return
<LF>              Line Feed
<Esc>E            Printer Reset
<CR>              Carriage Return
<LF>              Line Feed

Note that the Carriage Return (hexadecimal 0D) and Line Feed (hexadecimal 0A) characters are not really required in this file - they are probably there as a consequence of how the PCL file was saved.
 
Is anyone aware of a good way to embed the binary into a text file programmatically? We work with Unix, Windows, or Javascript/HTML.

 
it depends on the programming language.

In c, if you want 0x00, then aa=0; 0x08 aa=8;

In Basic, 0x00 aa=chr$(0), 0x08 aa=chr$(8), 0xA2 aa=chr$(162)

Bourne shell, 0x00 aa=`echo "\000"` 0x08 aa=`echo "\010"` 0xA2 aa=`echo "\242"`
Note that those are 3 digit octal values after the "\"

As I sugested earlier put in ascii placeholders and later edit with a Hex editor; e.g.,

<esc>*v6WXXXXXX

Then with the hex editor change the XXXXXX to 00 01 02 08 08 08


Jim Asman
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top