Using filesystem components to implement locally specific printing methods in Web applications-application techniques

Source: Internet
Author: User
1. Introduction
With the rapid development of Internet, many enterprises have developed a web-based business application system. Under normal circumstances, web-based business applications are three-tier or three-tier structure, the front is the client is a common web browser, the intermediary business logic application layer on the Web server, by the Web Server service artifacts access to the background database. To interconnect the business system with the Internet, both the Web server and the database system are hosted in the IDC (Internet Data Center), which requires the extraction of business data from the hosted server on IDC for local printout. In the case where the client browser can only print simple HTML pages, it requires a more powerful and flexible print output, and expands the browser's functionality by using related technologies to enable more complex data printing tasks such as receipts, receipts, and more. The author used the FileSystem component to realize the functions of collecting vouchers and admission ticket in local printing for a network education company when developing educational management software.
2, filesystem component use Introduction
The filesystem component is actually an ActiveX control that exists in the Windows platform (either Win98, Win2000, or NT environments contain the component.) ), clsid:0d43fe01-11cf-8940-00a0c9054228. Familiarity with ASP programmers may have used the filesystem component, which is typically used on the server side to access and control text files, folders, and drives. There are two ways to create an object instance of a filesystem component:
1, use the ASP's built-in Object Server method Server.CreateObject to create an instance of the server-side object.
2. Use the VBScript script function CreateObject to create an instance of the client object (or you can use the method on the server side, but sometimes it will be wrong, generally not used;).
The filesystem component operates on a text file in the following ways:
CreateTextFile (Filename,[overwrite if EXISTS],[UNICODE/ASCII])//Create a text file
OpenTextFile (Filename,[input/output mode],[create if not Exists],[format])//Open Text file
CopyFile (Filename1,filename2,[overwrite])//Copy text file
MoveFile (filename1,filename2)//Move text file
DeleteFile (Filename)//Delete text file
GetFile (Filename)//Get text file
FileExists (Filename)//To determine whether a text file exists
The filesystem component also has a way with folders and drives that are similar to text files, and don't repeat them here.
In fact, the filesystem component can also be used for clients, and the second way to create a FileSystem Component object instance is to access and control the text files, folders, and drives of the client system. Because the Microsoft platform has filesystem components, the client on the Microsoft platform does not need to download from a remote server, installs and registers itself when the operating system is installed, and installs Plug-ins and downloads filesystem components for clients on other platforms.
3, local-side specific printing implementation mechanism
The process of implementing a local-side-specific printing using the FileSystem component is shown in the following illustration:


1, the client sends the data request to the Web server;
2. The Web server interacts with the background database according to business processing logic, obtains the required data to form an HTML page, and with a VBScript script with FileSystem component objects, sends back the HTML page to the client browser;
3, the client runs the script, the script obtains the HTML page component the data, establishes the connection with the printer, prints the data to the printer output.
The first two steps are no different from a typical Web application, and the third step is to create an instance of the FileSystem Component object using the VBScript script function CreateObject, and then call the instance to create the CreateTextFile method of the text file. Set the print port LPT1 or LPT2 as the filename parameter and set the overridden file argument to true to establish a connection to the printer; The write-text method that invokes the obtained printer text file stream instance writeline the content printed to the printer output.
4. Program Example
Client script:
<script language=vbscript>
function Print_onclick//print functions
Dim label
Label=document.printinfo.label.value//Access to HTML page data
Set Objfs=createobject ("Scripting.FileSystemObject")//Create an instance of the FileSystem Component object
Set OBJPRINTER=OBJFS. CreateTextFile ("LPT1:", true)//establish a connection to the printer
Objprinter. Writeline ("__________________________________")/output printed content
Objprinter. Writeline ("| |")
Objprinter. Writeline ("| The data you printed is: "&label& |"
Objprinter. Writeline ("| |")
Objprinter. Writeline ("|_________________________________|")
Objprinter.close//Disconnect from the printer
Set objprinter=nothing
Set objfs=nothing//close FileSystem Component Object
End Function
</script>
Server-side scripting:
<% .....
Set Conn=server. CreateObject ("Adodb.connection")
Conn. Open "Dsn=name; uid=xxxx; pwd=xxxx; "
Set Rs=server. CreateObject ("Adodb.recordset")
Rs. Open ("Select ..."), conn,1,1
..........%>//interacting with the database
HTML page encoding:
<HTML>
.........
<form id=printinfo name= "Printinfo" >
<input type= "button" value= "Print >>" Id=print name=print >//Call print function
<input Type=hidden id=text1 Name=label value=<%=.........%>>//Save data from server side
.........
</HTML>
5. Description and conclusion
1. Before you can use this method to implement print tasks, you must adjust your browser's security settings, reduce the level of security on your Internet options, fully trust your site, and perform scripts to access native resources through your browser.
2, this method can be used to print remote server data on the local area network printer, only need to use the local Area network printer registration port in place of the local printer port as the CreateTextFile method to create the text file parameters.
3, this method can be achieved according to the user to choose the width, height and number of printing and content, and can be repeated printing.
4, do not need to write ActiveX control that can complete a specific printing function, the implementation is simpler.
5, the disadvantage is that you need to adjust the browser security settings, and does not support the printing of pictures and special fonts.

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.