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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sample/Information for PCL or PJL line/box drawing (HP Laserjet) 2

Status
Not open for further replies.
Jun 15, 2002
31
0
0
US
I'm working on a project and need info on box drawing and line drawing
in PCL or PJL for HP Laserjet 4350 series printers. We need to manually code
to fit custom forms and data.
Samples would be great. I have found the PJL code PD, PU and SD but need to know the
parameters.
Thanks
 
I do this all the time.

Simply get the PCL5 technical reference, and read up on the rectangle codes
in the form <esc>*c####a####b0P where the value before the a is the width and
that before the b is the depth of the rectangle. The values are in user units,
typically 300 dpi.

So a horizontal line 3 inches wide would be <esc>*c900a5b0P while a vertical line
3 inches high would be <esc>*c5a900b0P. If you properly position the cursor,
four lines can be positioned so as to reate a box. Adjust the small number for
a thinner or bolder line.

Much of this is easier is HP-GL/2 which is also covered in the reference.





Jim Asman
 
Hi Jlasman;

Followed your instructions and I have the top, bottom and left vertical.
Can't seem to reposition the row/column to perform the right vertical line.

I have four rectangles that need to be made horizontally.
Here's my sample code:
0022: print hp.default.page:hp.eol
0023: *
0024: * Top Horizontal Line
0025: print hp.esc:char(42):char(99):'600':char(97):'5b0':char(80)
0026: *
0027: * Reposition for Vertical
0028: print hp.esc:char(42):char(112):'0':char(120):'145':char(89):hp.eol
0029: * Vertical Line
0030: print hp.esc:char(42):char(99):'5a':'300':'b0':char(80)
0031: *
0032: * Reposition for Bottom Horizontal Line
0033: print hp.esc:char(42):char(112):'600':char(120):'450':char(89):hp.eol
0034: * Bottom Horizontal Line
0035: print space(3):"Where am I ?"
0036: print hp.esc:char(42):char(99):'600':char(97):'5b0':char(80)
0037: * Reposition for Right Vertical Line
0038: print hp.esc:char(42):char(112):'500':char(120):'600':char(89):hp.eol
0039: print hp.esc:char(42):char(99):'5a':'300':'b0':char(80)
0040: * Write it out
0041: print hp.esc:char(69):hp.eol

Note: hp.esc=char(12), hp.eol=char(13):char(10)

Thanks,
 
Other than the <esc> the rest is all ascii. So it looks as though you want a box that is 600 pixels wide by 500 pixels high do this...

hp.esc:"*c600a5b0P" #Draw Top Horizontal line
hp.esc:"*c5a500b0P" #Draw Left vertical line
hp.esc:"*p+600x+500Y" #Position cursor to the bottom right of box relative move
hp.esc:"*c-5a-500b0P" #Draw right vertical up. Note the minus signs
hp.esc:"*c-600a-5b0P" #Draw bottom line to left Note minus signs
hp.esc:"*p-600x-500Y" #Return cursor to origin at top left

There is only one cursor move in the drawing of the box and a traiing one
at the end to restore the origin.

I'm not sure of yor language, so perhaps the double quotes " need to be singles '
I assume that hp.esc delivers char(27).

In HP-GL/2, that box could be done with ER600,500; and without any cursor move


Jim Asman
 
Hi Jlasman;

Thanks for the info.. I entered the info as presented but the result gave me a
horizontal line and a left vertical line, then another lower horizontal line (with a few
<lf> and another left vertical line.

This is the problem that I have been encountering. It doesn't seem to be recognizing
the row and column (x/y) positioning.

I will need to have the rectangles, 750 x 300, on a horizontal plane with line drawing below it.

Current result:
-----------------------------
|
|
|
|

-----------------------------
|
|
|
|

Thanks,,
 
But your cursor positioning seems to be to an absolute address with the origin at 0x0y rather than an address relative to the origin that is somewhere else on the page.. It is awfully hard to interpret your code when you don't directly display the ascii characters. Perhaps you could post the actual PCL the your code is generating and then we could tell exactly is going on.

Did you try the method in the pseudo code that I posted?

Jim Asman
 
Hi Jlasman;

Here's the output captured (ignore the line numbers):
0001:
0002:
0003:
0004: ^027E
0005:
0006: ^027&l1O
0007:
0008: ^027&l5.45C
0009:
0010: ^027*c600a5b0P
0011: ^027*c5a500b0P
0012: ^027*p+600x+500Y
0013: ^027*c-5a-500b0P
0014: ^027*c-600a-5b0P
0015: ^027*p-600x-500Y
0016: ^027E

Here's the code:
0019: hp.esc=char(27)
0020: print hp.esc:char(69):hp.eol ; * Reset
0021: print hp.landscape.mode:hp.eol
0022: print hp.default.page:hp.eol
0023: *
0024: print hp.esc:"*c600a5b0P" ; * Draw Top Horizontal Line
0025: print hp.esc:"*c5a500b0P" ; * Draw Left Vertical Line
0026: print hp.esc:"*p+600x+500Y" ; * Position Cursor to bottom Right of box (Relative)
0027: print hp.esc:"*c-5a-500b0P" ; * Draw Right Vertical Up (Minus Sign)
0028: print hp.esc:"*c-600a-5b0P" ; * Draw Bottom Line to Left (Minus Sign)
0029: print hp.esc:"*p-600x-500Y" ; * Return Cursor to Origin at Top Left
0030: print hp.esc:char(69):hp.eol

Thanks
 
I apologize. You cannot draw a line up or to the left in PCL. You can in HP-GL/2.

This means that we have to visit a 3 of the 4 corner positions of the proposed box. Attached is a printable file. But lets go through it.

<esc>"*p500x500Y" #Initial position
<esc>"*c600a5b0P" #Draw top line
<esc>"*c5a500b0P" #Draw left line
<esc>"*p+500Y" #Move to bottom left corner
<esc>"*c600a5b0P" #Draw Bottom line
<esc>"*p+595x-500Y #Move to top right
<esc>"*c5a500b0P" #Draw Right line
<esc>"*p-595X #Return to origin

Note the the move to the right side was only 595 and not 600. This is to position the verttical line there inside the top and bottom line. In fact the vertical move dhould have only been 495 if our box size was to include the the thickness of the lines themselves.

If yours doesn't work compare your pcl to the attached file that WILL print properly.

Carry on!


Jim Asman
 
There is a shorter way to create a box in PCL. Basically we draw a solid black box to the desired dimension. Then move the cursor inside that box 5 pixels each way and then draw an appropriately smaller "white" box that erases the interior of the big black box, leaving the outside 5 pixel perimeter 5 pixels. So ...

<esc>"*p500x500Y" #Initial position
<esc>"*c600a500b0P" #Draw big black box
<esc>"*p+5x+5Y" #Reposition cursor
<esc>"*v1o1T" #Set mode to print "white" opaquely
<esc>"*c590a490b0P" #Draw smaller white box leaving ruled rectangle
<esc>"*v0o0T" #Restore black print
<esc>"*p-5x-5Y" #Restore cursor to origin

WARNING!!! If there is to be text printed inside the box, then the box MUST be laid down BEFORE the text is printed; otherwise, the text would be erased by the creation of the box. This method then would not be appropriate for an aotomatic overlay as the overlay is run after the page has been imaged.



Jim Asman
 
Hi Jlasman;

Using the latest code provided I just get the black box.
It does not produce the white area revealing only the border.

Thanks,
 
I'm sorry, I didn't test it.

Change the code that reads...
<esc>"*c590a490b0P"
to
<esc>"*c590a490b1P"

You are only changing the end to 1P from 0P

1P indicates a white fill and 0P a black fill

A demo file is attached

Jim

Jim Asman
 
Jim;

The result is a black box.
Here's my test code:
0009: printer on
0010: print hp.esc:char(69):hp.eol ; * Reset
0011: print hp.landscape.mode:hp.eol
0012: print hp.default.page:hp.eol
0013: print hp.esc:"*p500x500Y":hp.eol
0014: print hp.esc:"*c600a500b0P":hp.eol
0015: print hp.esc:"p+5x+5Y":hp.eol
0016: print hp.esc:"v1o1T":hp.eol
0017: print hp.esc:"c590a490b1P":hp.eol
0018: print hp.esc:"v0o0T":hp.eol
0019: print hp.esc:"*p-5x-5Y":hp.eol
0020: printer off
0021: printer close

Thanks,
Steve
 
Jim;
I'm still struggling with this.
The goal is to layout 3 rectagles on the 'X' axis and then print data in each of the rectangles.
Each rectangle size is 750x300 with a 300 unit space between each rectangle (2 spaces)
I can print the separate rectangles vertically, but I lose positioning with printing across the 'X' axis.
This is my sample code based on your example sent the other day.
0010: print hp.esc:char(69):hp.eol ; * Reset
0011: print hp.landscape.mode:hp.eol
0012: print "Landscape Mode"
0013: print hp.default.page:hp.eol
0014: *
0015: print hp.esc:"*p0x350Y":hp.eol ; * Initial Position
0016: print hp.esc:"*c750a300b0P":hp.eol ; * Draw Big Black Box
0017: print "Box 1, done"
0018: *
0019: * Box 2
0020: print hp.esc:"*p0x750Y":hp.eol ; * Initial Position
0021: print hp.esc:"*c750a300b0P":hp.eol ; * Draw Big Black Box
0022: *
0023: * Box 3
0024: print hp.esc:"*p0x1150Y":hp.eol ; * Initial Position
0025: print hp.esc:"*c750a300b0P":hp.eol ; * Draw Big Black Box

After laying out the form I need to go back and drop in the text.
Thanks,
GrotonGroup
 
Your problem is probably the "eol", which likely issues a CR which would move mthe cursor back to the left margin.
 
Thanks for the info, but my end of line = char(10).

Currently, the boxes print the correct sizes but the run down the left vertical side, not three(3) across
on the horizontal plane. My first one starts at 0,350 then next box should be to the right of the first one and then
the last box to the right of that one.

I'm sure it has to do with eith the absolute or realtive coordinates.
Any assistance is greatly appreciated.

GrotonGroup
 
One handy aspect of the rectangle command is that it doesn't change the
cursor. Any LFs shown here are for clarity and should not be in the PCL
code. A working file, tribox.pcl is attached.Try this ...

<esc>*p0x350Y
<esc>*c750a300b0P<esc>*p+1050X<esc>*c750a300b0P<esc>*p+1050X<esc>*c750a300b0P
<esc>*p5x355Y
<esc>*c740a340b1P<esc>*p+1050X<esc>*c740a340b1P<esc>*p+1050X<esc>*c740a340b1P
<esc>*p0x350Y

What we are doing is this

1. Draw black box, move relative +1050 dots, draw middle black box, move +1050 dots,
draw third black box.

2. Put cursor 5 dots inside left box, then draw white box, move +1050 dots,
draw middle white box, move +1050 dots, draw third white box.

3. Reposition cursor back to origin.

If any of the code lines wrap here, make your window wider.

Let me know how you make out.
~
~

Jim Asman
 
Jim;
Thank you... Definite progress is being made.
I'll be tweaking it now.
Thanks for your assistance.
GrotonGroup
 
Jim;

I'd like to draw three(3) vertical lines below the boxes that you indicated.
They will be printed in landscape mode at coordinates 0,2750 / 0,2125 / 0,275

I appear to be getting a top-of-form and change back to portrait.
Suggestions.

Here's the latest code:
0010: printer on
0011: print hp.esc:char(69) ; * Reset
0012: print hp.landscape.mode
0013: print "Landscape Mode"
0014: print hp.default.page
0015: *
0016: print hp.esc:"*p0x370Y"
0017: print hp.esc:"*c750a300b0P":
0018: print hp.esc:"*p+1075X":
0019: print hp.esc:"*c750a300b0P":
0020: print hp.esc:"*p+950X":
0021: print hp.esc:"*c750a300b0P"
0022: * End Black Rectangles
0023: print hp.esc:"*p5x375Y"
0024: print hp.esc:"*c745a290b1P":
0025: print hp.esc:"*p+1080X":
0026: print hp.esc:"*c740a290b1P":
0027: print hp.esc:"*p+950X":
0028: print hp.esc:"*c740a290b1P":
0029: *-- print hp.esc:"*p0x350Y"
0030: * Do the lines in here
0031: print hp.esc:"*p0x2750Y":
0032: print hp.esc:"*c1100a6b0P"
0033: print hp.esc:char(69)
0034: printer off
0035: printer close

Once again, Thank You
GrotonGroup
 
I need to see the details of your landscape command are.

The code you show, cannot draw the boxes correctly. The +#### dot move to the middle and end box must be the same for both the black boxes and white boxes. That gap does NOT change because the white box is smaller.

0x2750Y is off the bottom of a landscape page. The line that you draw in the code above is horizontal not vertical.

Really, to explain the behavior of your code, I need to see the actual print stream that goes to the printer. So, print to a file and attach that file to your reply, not your translation of your source code.

Jim Asman
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top