Setting printer paper length using unix commands

Hi Guys,
I have been trying to resolve a printing problem but nothing works out .
I have an Epson LQ 680 (dot matrix printer) . I need to print a file . The paper length should be 34 .Left margin should be 5. I have tried the following things after researching from the man pages.

pr -t -l34 -o5 fileName | lp
lp -dprintername -olength=34 -onopagebreak fileName

But in both these cases i get a problem where in the first page is printed properly but the second page and pages after spits out blank lines and it doesn't obey the page length .
My other case was

pr -F -o5 fileName | lp

where form feed characters are read properly amd aligned but the printer takes default length of paper size as 66. I need to override this paper length settings through shell script whenever i print.
Since other applications use the same printer i can't set the page size in the server .

I am using HP - UX , Bourne Shell.

I heard that we can echo the printer settings in unix.I have the printer codes in Hexa decimal values. (\x1B\x43\x21)

Have tried using

echo $
echo ""

But nothing is working.I am a newBee to Unix .

Any help on how to echo the printer page length dynamically using any unix commands .

---------- Post updated 12-18-11 at 11:41 AM ---------- Previous update was 12-17-11 at 09:53 PM ----------

Has anyone faced this issue Guys .Please let me know if so.. Thanks

What HP-UX version?
How is configured the printer?

This seems to be a 10-year-old printer for DOS and early Windows.
Epson LQ-680Pro, Documents & Manuals - Technical Support - Epson America, Inc.

Which HP computer?
Which HP-UX version?
How is this printer physicaly connected to the HP computer?
If it is actually connected to the network, how is this achieved and is there a HP Jet Direct Box?
If it is actually connected to a Windows server, please describe how that is configured and how the HP-UX server sends print.
How was the print queue installed in HP-UX? Was there any special printer driver software for HP-UX from Epson?

Addendum: That Escape sequence looks familiar (standard Epson one).
 (\x1B\x43\x21)         Is the same as ESC C 33   (set page length to 33 lines.

We have to work in Octal for the Escape Character and the Number in Shell.

If you don't have a special Epson print filter and you wish to send that escape sequence before your printout file called "fileName":

(
echo "\0033C\0041\c"
cat fileName
) | lp -d printername    ....etc

However of there is some other driver there it will override your settings. Really need to know everything about how this printer is configured. In practice you will probably end up sending a whole list of Escape Sequences to get this right.

1 Like

Thanks guys for the reply. I am using HP-UX 11i V3.

The printer is configured in a Windows XP machine and remotely connected to unix server.There is no HP DirectBox(Windows machine acts as one).

The printer is remotely connected to the LPD port.

No special driver from Epson. It's just the same HP - UX remote printer driver.

Configured as a remote printer, the HP-UX knows nothing about the printer except its hostname (or IP...), therefore ignores all options you would try to send... (man lp and specially 1m rlp ...).
I did long ago (>10 years...) configure a laserjet in such a way, so I know you could "encapsulate" PCL in the file to print but would an Epson accept the HP PCL?

1 Like

I hope it's a kind of a no.:frowning: . But i would like to try that option instead of thinking . Can you please let me know how to encapsulate PCL into the file.

You mean to say through some escape codes like <FF><DC2> .

The easiest would be to write a script that would parse the give lp option, create the PCL sequence and put that in head of a new file, append the the to print perhaps rename the final file in /tmp and send that to the spool...
some sequences:

LANDSCAPE="^[&l1O"
WRAP="^[&s0C"
SMALL="^[(s16.66h7V"
2SIDES="^[&l1S"
MARGIN="^[&a"
NOLOGO="^[&f1y8X"
RESET="^[E"
BIGCHAR="^[(s1p16v0b4148T"
DEFLT_FNT="^[(8U^[(s0p12h10v0s0b3T"
BEGIN="^[&l26A"

Or create a string sequence to send to the printer, then send the files to print, then reset the printer...

1 Like

My version of the basic technique is in post #3.

How is the Windows printer configured? Does it have the Epson driver loaded and a configuration screen where you can change the page size? Or is it just configured as a dumb network printer?

Diagnostics:
Your printer should have a diagnostic mode where it prints all escape sequences rather than executing them. This is one way to find out if Windows is sending setup escape sequences to the printer - and what they are.

1 Like

You should also add an additional escape sequence to return the printer to its power on settings at the end of the job, otherwise, every job will have to set its own page length.
Try setting the printer as a Generic text only printer within XP so that the Windows driver does not add additional escape sequences.

( echo "\0033C\0041\c"
 cat fileName
echo "\0033@\c"
 ) | lp -d printername    ....etc

1 Like

EPSON LQ 680 / ESC P2 driver is loaded and i am able to change the page size . Infact i am able to see lots of options. Have tried over different sizes like A4,A5 Letter , etc . Also in the printer DIP settings i am able to set the printer page length and other options like Perforation , etc. Have changed and tried all those combinations. But was still unsuccessful.

---------- Post updated at 07:52 PM ---------- Previous update was at 06:59 PM ----------

After executing the following command ,

( echo "\0033C\0041\c"
 cat fileName
echo "\0033@\c"
 ) | lp -d printername   

i see an empty box which is the form feed character and "C!" printed along with the data.

It seems that the printer is not recognizing the code or maybe i am wrong somewhere .

Looks like it is reading the escape sequence as "Esc C !" (i.e. taking octal 041 to mean character ! - not decimal 33).

Time to get hold of the manual for your printer. The first thing to check is what mode the printer is in.
(My codes came from an Epson LQ850+ manual and were used in a live script to print awkward sized labels).

I have had terrible trouble with this subject in the past because Epson marketed some printer model variants which responded to non-Epson control codes. (e.g. IBM codes) while they were trying to get market share. You can only tell from the part number.

1 Like

Is there any difference in configuring the printer in unix server in LPR port and USB ?

How to identify whether the commands i execute from unix is properly received by the port and forwarded to printer?

Sorry but this question makes no sense whatsever. There is no such thing as a "LPR port".

Get the manual for your printer and find out how to put the printer into diagnostic mode where it will print any Escape Sequences rather than action them.

There is a massive difference when a Microsoft Windows computer is involved. Personally I have not configured a "LPR" printer in the last 20 years (it is very old technology).
Nowadays we expect the printer to be directly connected to the network. When it is an old dot-matrix printer we expect it to be connected to the network via a HP Jet Direct box.

1 Like

Merry Christmas Guys. Still i have alignment issues in printing. Will update the post once i get the solution. Any other suggestions please help. Thanks

echo "\0033C\0041\c" >set33

confirm that file set33 contains 3 characters using a hex or octal dump program. Hex dump should look like 1b 43 21.
Do the same with the printer reset.

echo "\0033@\c">reset

If you have the gnu version of echo, will you have to use "echo -e" instead of "echo"
Change the unix printer script to:

cat set33 myprintfile reset |lp -depson

Change the Windows printer configuration to temporarily print to file. Send a print job to the printer, and examine the file using "debug"

1 Like

Thanks Jack,
That commands were pretty useful . Got some clear idea . But i still find those datas also appended in the print file.

Are there also escape sequences in the original print file? If so they will override whatever commands you prefix the file with. Can you save the original print file, and post the first 3 lines, and the last 3 lines?

1 Like

The file looks like below .
The file starts with two line feeds at the beginning . The first three lines are

line feed 
line feed
                    065                                       13-Dec-2011

The last three lines for this page are

         P O BOX 46806 ABU DHABI
          
         ABU DHABI,          Abu Dhabi
[FF]

where [FF] form feed character is displayed as a Box .

There are multiple pages like this inside a single file. I need to print each page separately reading from the same file .

Lets bypass all the intermediate processes.
Save the print file to disk.
Edit the file so that only two pages are printed.

cat set33 saved_print_file reset >testfile

Go to the XP machine.
Start a command prompt
FTP to the HPUX machine and login.
ftp>ascii
ftp>get testfile
ftp>quit
c:> copy testfile LPT1:
I am assuming that the printer is connected to the primary parallel port of the computer. Otherwise, use the appropriate device (LPT2:, COM1:, COM2:)

1 Like

It is connected to a USB port . When i mention USB002(name of the port to which printer is configured) it is giving me an error( * Is not a recognized device). When i give the printer name instead of port name it is asking whether to overwrite the file with options as Yes /No/All . I have a doubt wherein it will overwrite any printer settings or just the datas in printer queue . (Coz the printer queue is empty right now and then also it is aking the same)