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!

replace dot matrix printer with laser printer

Status
Not open for further replies.

AzizKamal

Programmer
Apr 6, 2010
122
PK
In an asp application, there is a Print Receipt button. Clicking this button goes to a printerlocation.asp page. Here printer location is selected in the format \\computername\printersharename. Upon clicking the Submit button on printerlocation.asp page, it goes to printreceipt.asp page. This page prints the receipt to a dot matrix printer.

To accomplish dos based printing, dos based printing software is installed. Once this software is installed, the following line is written on printreceipt.asp page:

Code:
set dosprint=server.CreateObject("FastPrint.Writer")

When I type dosprint. I see two methods; WriteOnPrinter and PrinterClose. I also see one property; Printername.
So, a sample code to send output to dot-matrix printer is as follows:

Code:
set dosprint=server.CreateObject("FastPrint.Writer") 
dosprint.Printername=printer1
call connect()
dosprint.WriteOnPrinter "abc" 
Response.End

This will send output abc to dot matrix printer.

This had been done earlier by another developer and now I have to replace the dot matrix printer and send the same output to laser printer.

We are using Windows XP Service Pack 2. I installed HP LaserJet 1320 printer and captured LPT1 port as follows:

1. Opened the printer’s properties page
2. Selected the Sharing tab
3. Selected Share this printer radio button
4. Type hp3 in Share name box and clicked OK
5. Opened the command prompt and typed net use
6. This showed all the mappings that I currently have
7. Typed net use /delete lpt1
8. Typed the following on command prompt:
net use lpt1: \\computername\hp3 /persistent:yes

Now I run the asp application and gave \\computername\hp3 in printerlocation.asp page. Upon clicking the submit button, output abc appeared correctly on HP Laser Printer.

The issue that I am facing is that in printreceipt.asp, to output say 3 lines, carriage return and line feed characters have been used. For example, to output three lines to dot matrix printer, code would be as follows:

Code:
dosprint.WriteOnPrinter "aaa" & chr(10) & chr(13) 
dosprint.WriteOnPrinter "bbb" & chr(10) & chr(13) 
dosprint.WriteOnPrinter "ccc"

This would print three lines on dot matrix printer. But when I tried this code to see the output on HP Laser Printer, I got aaa on first page, bbb on second page and ccc on third page. I need to achieve LineFeed and Carriage Return on Laser Printer.





 
Hi,
Did you try without the line feed?



[profile]

To Paraphrase:"The Help you get is proportional to the Help you give.."
 
to me it looks like you are sending "raw" characters to the HP. The formatting codes for matrix and laser printers are completely different. For the HP you need PCL5 escape codes.
Have a look at:
 
Thanks.

I tried without Line Feed too but again got three pages in all the following combinations:

Code:
dosprint.WriteOnPrinter "aaa" & chr(13)
dosprint.WriteOnPrinter "bbb" & chr(13)
dosprint.WriteOnPrinter "ccc"

dosprint.WriteOnPrinter "aaa" & chr(10)
dosprint.WriteOnPrinter "bbb" & chr(10)
dosprint.WriteOnPrinter "ccc"

dosprint.WriteOnPrinter "aaa"
dosprint.WriteOnPrinter "bbb"
dosprint.WriteOnPrinter "ccc"

On this website:

Printer Command Language has following codes for Line Termination:

PCL Line Termination
Ec&k0G CR=CR LF=LF FF=FF
Ec&k1G CR=CR+LF Lf=LF FF=FF
Ec&k2G CR=CR LF=CR+LF FF=CR+FF
Ec&k3G CR=CR+LF LF=CR+LF FF=CR+FF

I tried the following:

Code:
dosprint.WriteOnPrinter chr(27) & chr(38) & chr(107) & chr(48) & chr(71)
dosprint.WriteOnPrinter "aaa" & chr(13) & chr(10)
dosprint.WriteOnPrinter "bbb" & chr(13) & chr(10)
dosprint.WriteOnPrinter "ccc"
[blue]got 3 pages with aaa on 1st, bbb on 2nd and ccc on 3rd[/blue]

dosprint.WriteOnPrinter chr(27) & chr(38) & chr(107) & chr(49) & chr(71)
dosprint.WriteOnPrinter "aaa" & chr(13)
dosprint.WriteOnPrinter "bbb" & chr(13)
dosprint.WriteOnPrinter "ccc"
[blue]got 3 pages with aaa on 1st, bbb on 2nd and ccc on 3rd[/blue]

dosprint.WriteOnPrinter chr(27) & chr(38) & chr(107) & chr(50) & chr(71)
dosprint.WriteOnPrinter "aaa" & chr(10)
dosprint.WriteOnPrinter "bbb" & chr(10)
dosprint.WriteOnPrinter "ccc"
[blue]got 3 pages with aaa on 1st, bbb on 2nd and ccc on 3rd[/blue]

dosprint.WriteOnPrinter chr(27) & chr(38) & chr(107) & chr(51) & chr(71)
dosprint.WriteOnPrinter "aaa" & chr(13)
dosprint.WriteOnPrinter "bbb" & chr(13)
dosprint.WriteOnPrinter "ccc"
[blue]got 3 pages with aaa on 1st, bbb on 2nd and ccc on 3rd[/blue]

dosprint.WriteOnPrinter chr(27) & chr(38) & chr(107) & chr(51) & chr(71)
dosprint.WriteOnPrinter "aaa" & chr(10) & chr(13) & "bbb" & chr(10) & chr(13) & "ccc"
[blue]with this I got 3 lines aaa, bbb, ccc on a single page[/blue]

dosprint.WriteOnPrinter "aaa" & chr(10) & chr(13) & "bbb" & chr(10) & chr(13) & "ccc"
[blue]it worked even without sending PCL codes and I got 3 lines aaa, bbb, ccc on a single page[/blue]

so one solution that came to my mind is to store everything to be printed in a variable, say str1 and issue only one dosprint.WriteOnPrinter command.

But that will require modifications in lot of reports and there must be some maximum length of vbscript variant variable…
 
I ended up sending output to screen and giving the Print Option to users in all reports.

There were the following major changes:

1. dosprint.WriteOnPrinter replaced with response.write
2. chr(13) & chr(10) replaced with "<br>"
3. use of HTML tables
4. for Go To Main Menu, I used anchor tag on the statement, Computer generated receipt signature not required
5. for Print option, I used anchor tag on Print by text:

Code:
Response.Write "<td width='72%'><a href=javascript:print(this.form)>Printed By:</a> " & trim(session("username")) & "</td></tr>"

6. For page breaks, I used CSS page-break-after Property:

Code:
Response.Write "<td width='72%' align='right' style='page-break-after:always'>Continue...</td><tr>"



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top