Re: Done! (11947 Views)
Reply
Occasional Contributor
MauriCBA
Posts: 4
Registered: ‎12-08-2013
Message 1 of 7 (12,073 Views)
Accepted Solution

PCL5 sample code to print single text in RGB color

Hi all,

 

I need to print PCL5 text in RGB color.

 

I'm currently using the simple color command Esc *r3U  Esc *v1S (red)Esc *v2S (green),...., etc. but I need to use RGB colors instead of factory-preset colors.

 

Could you please provide a sample PCL code to print a word, "Test" in different RGB colors?

 

Thanks in advance.

Honored Contributor
Chris H
Posts: 3,968
Registered: ‎06-04-2004
Message 2 of 7 (12,032 Views)

Re: PCL5 sample code to print single text in RGB color

[ Edited ]

To define your own colours, you need to make use of PCL Imaging mode (or the equivalent HP-GL/2 Imaging mode); this is described in the PCL5 Colour Technical Reference manual.

 

The following link provides a brief history of the PCL language, and links to the PCL Colour Technical Reference manual, and also to other PCL5 & PJL manuals: http://h20000.www2.hp.com/bizsupport/TechSupport/Document.jsp?objectID=bpl04568 


PCL Imaging mode requires that:

 

  • The Configure Image Data escape sequence be used to define the colour space, and create a programmable palette; this sequence has associated binary data; there is a short form (supported on most devices), and a long form, which may only be relevant to specific devices.
  • The programmable palette may then be modified using the Colour Component One/Two/Three and Assign Colour index escape sequences.

There are a number of other colour commands (some of which are relevant only to specific devices) to control colour mapping, dithering, etc.

Honored Contributor
Chris H
Posts: 3,968
Registered: ‎06-04-2004
Message 3 of 7 (12,031 Views)

Re: PCL5 sample code to print single text in RGB color

[ Edited ]

The following pseudo-PCL (with interpretation) makes use of the above PCL Imaging Mode commands to print some text in each of 8 different colours (i.e. an eight-colour programmable palette is defined); the first seven colours are 'pure' colours (Black, Red, Green, Blue, Cyan, Magenta, Yellow) and the eighth is set to a custom colour:

 

<Esc>E            Printer Reset
<Esc>&u600D       Unit-of-Measure (600 PCL units per inch)
<Esc>*v6W         Configure Image Data (data length = 6)
[ 6 bytes ]       Configure Image Data header: [ 00 01 03 08 08 08 ]
                  Color Space                              0: Device RGB
                  Pixel Encoding                           1: Indexed by Pixel
                  Bits/Index                               3: palette size = 8
                  Bits/Primary 1                           8
                  Bits/Primary 2                           8
                  Bits/Primary 3                           8
<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)
       0b         Colour Component 2 (primary value = 0)
       0c         Colour Component 3 (primary value = 0)
       1I         Assign Colour Index (index = 1)
<Esc>*v0a         Colour Component 1 (primary value = 0)
       255b       Colour Component 2 (primary value = 255)
       0c         Colour Component 3 (primary value = 0)
       2I         Assign Colour Index (index = 2)
<Esc>*v0a         Colour Component 1 (primary value = 0)
       0b         Colour Component 2 (primary value = 0)
       255c       Colour Component 3 (primary value = 255)
       3I         Assign Colour Index (index = 3)
<Esc>*v0a         Colour Component 1 (primary value = 0)
       255b       Colour Component 2 (primary value = 255)
       255c       Colour Component 3 (primary value = 255)
       4I         Assign Colour Index (index = 4)
<Esc>*v255a       Colour Component 1 (primary value = 255)
       0b         Colour Component 2 (primary value = 0)
       255c       Colour Component 3 (primary value = 255)
       5I         Assign Colour Index (index = 5)
<Esc>*v255a       Colour Component 1 (primary value = 255)
       255b       Colour Component 2 (primary value = 255)
       0c         Colour Component 3 (primary value = 0)
       6I         Assign Colour Index (index = 6)
<Esc>*v255a       Colour Component 1 (primary value = 255)
       192b       Colour Component 2 (primary value = 192)
       0c         Colour Component 3 (primary value = 0)
       7I         Assign Colour Index (index = 7)
<Esc>(19U         Primary Font: Symbol Set (19U = Windows Latin 1 (CP 1252))
<Esc>(s1p         Primary Font: Spacing: Proportional
       24v        Primary Font: Height (24 points)
       0s         Primary Font: Style (Upright, solid)
       0b         Primary Font: Stroke Weight: Medium
       16602T     Primary Font: Typeface (16602 = Arial)
<Esc>*v0S         Foreground Colour (index = 0)
<Esc>*p300x       Cursor Position Horizontal (300 PCL units)
       300Y       Cursor Position Vertical   (300 PCL units)
CID 8-colour palette:
<Esc>*v0S         Foreground Colour (index = 0)
<Esc>*p600x       Cursor Position Horizontal (600 PCL units)
       600Y       Cursor Position Vertical   (600 PCL units)
Palette index 0
<Esc>*v1S         Foreground Colour (index = 1)
<Esc>*p600x       Cursor Position Horizontal (600 PCL units)
       900Y       Cursor Position Vertical   (900 PCL units)
Palette index 1
<Esc>*v2S         Foreground Colour (index = 2)
<Esc>*p600x       Cursor Position Horizontal (600 PCL units)
       1200Y      Cursor Position Vertical   (1200 PCL units)
Palette index 2
<Esc>*v3S         Foreground Colour (index = 3)
<Esc>*p600x       Cursor Position Horizontal (600 PCL units)
       1500Y      Cursor Position Vertical   (1500 PCL units)
Palette index 3
<Esc>*v4S         Foreground Colour (index = 4)
<Esc>*p600x       Cursor Position Horizontal (600 PCL units)
       1800Y      Cursor Position Vertical   (1800 PCL units)
Palette index 4
<Esc>*v5S         Foreground Colour (index = 5)
<Esc>*p600x       Cursor Position Horizontal (600 PCL units)
       2100Y      Cursor Position Vertical   (2100 PCL units)
Palette index 5
<Esc>*v6S         Foreground Colour (index = 6)
<Esc>*p600x       Cursor Position Horizontal (600 PCL units)
       2400Y      Cursor Position Vertical   (2400 PCL units)
Palette index 6
<Esc>*v7S         Foreground Colour (index = 7)
<Esc>*p600x       Cursor Position Horizontal (600 PCL units)
       2700Y      Cursor Position Vertical   (2700 PCL units)
Palette index 7
<Esc>E            Printer Reset

 

Note that the values for the six bytes of data which follow the CID sequence are shown in hexadecimal format, followed by a brief interpretation of their meaning.

Honored Contributor
Chris H
Posts: 3,968
Registered: ‎06-04-2004
Message 4 of 7 (12,026 Views)

Re: PCL5 sample code to print single text in RGB color

Attached is the PCL file (disguised with an additional .txt extension, to allow it to be attached in this forum).

Honored Contributor
Chris H
Posts: 3,968
Registered: ‎06-04-2004
Message 5 of 7 (12,003 Views)

Re: PCL5 sample code to print single text in RGB color

[ Edited ]

For some (as yet) unknown reason, that file doesn't print as expected on my local LaserJet Pro 400 Colour MFP M475dn: the only lines printed (all in black!) are those with odd-numbered colour indices. 

 

Update: I still don't know why the original file (creating an 8-colour palette) doesn't work with my printer; it seems OK if I look at it with a commercial PCL Viewer applciation.

All that I can suggest that explains the symptoms is that the CID sequence is (for some unknown reason) considered to be invalid by the printer, and is hence ignored, so the printer reverts to the (default) black and white palette, where even colour indices map to White, and odd indices map to Black.  

 

 

The attached modified file (Colour_CID_02.prn, also disguised with an additional .txt extension) does print OK to that printer .

 

The only difference between this file and the previous one is that, within the Configure Image Data parameters, the Bits Per index value is set to 8 (indicating a palette size of 256), whereas in the original file the value was 3  (indicating a palette size of 8).

 

Also attached is an analysis of the new file.

Occasional Contributor
MauriCBA
Posts: 4
Registered: ‎12-08-2013
Message 6 of 7 (11,959 Views)

Done!

Thank you very much my friend. It works perfectly! you're a master!
 
One last question: could you send me some pcl5 pseudo-code for drawing bar charts and pie charts, from one o two data series?
 
Thanks in advance.
Honored Contributor
Chris H
Posts: 3,968
Registered: ‎06-04-2004
Message 7 of 7 (11,947 Views)

Re: Done!

>> ... could you send me some pcl5 pseudo-code for drawing bar charts and pie charts, from one o two data series? ...

 

I don't have any such samples, sorry.

 

For bar charts, you could probably use PCL5 Rectangular Area Fills (perhaps using Shaded fills), in conjunction with colour palettes.

 

For pie charts, it would probably be easier to use the HP-GL/2 vector language subset of PCL5

 

The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.