Web Printing Using ASP

Source: Internet
Author: User
<Div class = contentfont id = newaspcontentlabel style = "padding-Right: 10px; display: block; padding-left: 10px; padding-bottom: 0px; padding-top: 0px "> <% @ Language = VBScript %>
<%
Option explicit
The value of the submit button is saved in dim strsubmit "form.
Dim strprinterpath "form to save the value of the Network Printer path
Value of the user name in dim strusername "Form
Password value in dim strpassword "Form
Dim strmessage "form print content value
File System Objects in dim objfs "VBScript
Network object in dim ob1_shnet "wsh
Dim objprinter "Print Object
Strsubmit = request. Form ("Submit ")
%>
<HTML>
<Head>
<Meta name = "generator" content = "Microsoft Visual Studio 6.0">
</Head>
<Body>
<%
If strsubmit = "" then
%>
Note:
Because this is a demonstration, the NT account and password are transmitted in ASP by unencrypted means.
In actual use, the login process should be processed securely.
<Form action = "aspprint. asp" method = post id = form name = form>
<Table width = 100% align = center border = 0 cellspacing = 1 cellpadding = 1>
<Tr>
<TD align = right nowrap> network printer path: </TD>
<TD align = left nowrap> <input type = "text" id = printerpath name = printerpath
Value = "\\< domain >\< printer>"> </TD>
</Tr>
<Tr>
<TD align = right nowrap> Logon account: </TD>
<TD align = left nowrap> <input type = "text" id = username name = Username
Value = "<% = strusername %>"> </TD>
</Tr>
<Tr>
<TD align = right nowrap> logon password: </TD>
<TD align = left nowrap> <input type = "password" id = Password
Name = PASSWORD> </TD>
</Tr>
<Tr>
<TD align = right nowrap> enter the text you want to print: </TD>
<TD align = left nowrap> <textarea rows = 2 Cols = 20 id = message
Name = message> </textarea> </TD>
</Tr>
<Tr>
<TD align = right nowrap> </TD>
<TD align = left nowrap> <input type = "Submit" value = "Submit"
Id = submit name = submit> </TD>
</Tr>
</Table>
</Form>
After the preceding information is submitted, you can print it according to the following code.
<%
Else
"Get Response Information from form.
Strprinterpath = request. Form ("printerpath ")
Strusername = request. Form ("username ")
Strpassword = request. Form ("password ")
Strmessage = request. Form ("message ")
We will now use the VBScript FileSystemObject object and the wsh network object. The network object will
Give us the methods we need to open a printer connection, and the FileSystemObject will allow us to stream our
Output to the printer. We create these objects in the following code example:
Set objfs = Createobject ("scripting. FileSystemObject ")
Set ob1_shnet = Createobject ("wscript. Network ")
"Use wsh to connect to a network printer
Ob1_shnet. addprinterconnection "LPT1", strprinterpath, false, strusername, strpassword
"Use a file system object to use a printing device as a file
Set objprinter = objfs. createtextfile ("LPT1:", true)
"Send text to the Print Device
Objprinter. Write (strmessage)
"Disable printing device objects and handle error traps
On Error resume next
Objprinter. Close
"If an error occurs, close the print connection and output the error message.
If err then
Response. Write ("Error #" & CSTR (ERR. Number) & "& err. description)
Err. Clear
Else
"Operation successful, output confirmation Information
Response. Write ("<center> ")
Response. Write ("<Table width = 100% align = center border = 0 cellspacing = 1 cellpadding = 1> ")
Response. Write ("<tr> <TD align = right> <B> Print the message output: </B> </TD> ")
Response. Write ("<TD align = left>" & strmessage & "</TD> </tr> ")
Response. Write ("<tr> <TD align = right> <B> network printer path: </B> </TD> ")
Response. Write ("<TD align = left>" & strprinterpath & "</TD> </tr> ")
Response. Write ("<tr> <TD align = right> <B> Logon account: </B> </TD> ")
Response. Write ("<TD align = left>" & strusername & "</TD> </tr> ")
Response. Write ("</table> ")
Response. Write ("</center> ")
End if
"Cancel print connection
Ob1_shnet. removeprinterconnection "LPT1 :"
Set ob1_shnet = nothing
Set objfs = nothing
Set objprinter = nothing
End if
%>
</Body>
</Html> </div>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.