Text / Xie Kang
People who do web development must face a common problem, that is, printing. Indeed, relative to Windows desktop applications, Web applications have various restrictions, and technicians often encounter users or such needs during project development. People who have done desktop applications will be very familiar with crystal reports. Report controls such as Active Report, which not only has a simple and flexible design interface, but also a very powerful report function, which can meet the printing needs of various reports. WEB applications can only seek other solutions because of its special rendering. Now let's analyze the current Web print scheme:
Existing Web print control technology is divided into several options:
One. Custom control completion print
Implement printing with the WebBrowser control of IE
Implement printing with third-party controls
1, custom control method
Custom control mode uses VB or VC and other tools to generate COM components, and analyze printed source files with defined print formats to implement print. Only the generated component is downloaded and registered to the client, in order to be implemented on the client
print.
The difficulty is mainly to define the print format, how to analyze the printed source file. The existing preferred method is to use XML technology to completely solve problems, using XML to be very easy to define the text, tables, and other contents of the print target.
However, the development requirements of programmers are high, and the difficulty is relatively large.
2, use WebBrowser to implement Web printing
WebBrowser is a browser control of IE built-in without user downloads. The discussion of this document is the technical content about the IE6.0 version of WebBrowser control. The technical requirements associated with it are: the generation of print documents, page settings, and implementation of print operations.
(1), printing documents
1, client script method
Client scripts are divided into VBScript, JavaScript, JScript several scripting languages. Developing the syntax used by the application in IE JScript syntax, because it is almost no difference in JavaScript, so it can be called JavaScript (Similar JS below). Under normal circumstances, the JS is mainly used to achieve the analysis of the DOM document, and the DOM is a web document model that Microsoft. It is mainly used to implement web scripting programming.
Using JS to analyze the contents of the source page, extract the page elements you want to print and implement printed. By analyzing the contents of the source document, you can generate a print target document.
Advantages: The client independently completes the generation of print target documents, mitigating server load;
Disadvantages: The analysis of the source document is complex, and the print content in the source document should be agreed;
2, server-side program mode
The server-side program is mainly used to use the background code to read the print source from the database to generate a print target document. When the page is generated, it should also be appropriate to consider using CSS to implement forced paging control.
Advantages: You can generate a very rich print target document, and the content of the content of the target document is strong. Since the print content is obtained from the database, the generation operation is relatively simple;
Disadvantages: The server-side load is relatively large;
(2), page settings
Page settings mainly refer to the page distance, header, footer, paper and other content of the print document. Page settings will directly affect the generation effect of print document layout, so it has a close relationship with the generation of print documents. For example: form
The number of lines, size, position, font, etc.
The existing technology is to control the page settings using the IE6.0's built-in print template, which can have a very large impact on the print destination document. The print template can control the page distance, header, footer, parity page, and other content, and you can get the user's settings, and you can send the setting to the server side.
Print Template technology You can customize the preview window and print format to maximize the target documentation and printing. (3) Implementation of printing operations
The implementation of this feature is mainly using the webbrowser control function interface to implement print, print preview (default),
Page settings (default).