The existing web printing control technology is divided into several solutions
Print Custom Controls
Print using the webbrowser control provided by IE
Printing using third-party controls
The following describes the first two aspects.
I. Custom Controls
Custom Controls use tools such as VB or VC to generate COM components and use the defined print format to analyze and print the source files. Only by downloading and registering the generated components to the client can the generated components be printed on the client.
The difficulty is to define the print format and how to analyze the print source file. A better method is to use XML technology to completely solve the problem. XML can be used to easily define the format of the printed target text, table, and other content. However, it is difficult to develop programmers.
Ii. Web Printing Using webbrowser
Webbrowser is a browser control built in IE, which does not need to be downloaded by users. This document discusses the technical content of the webbrowser control of ie6.0. Related Technical requirements include generation of printed documents, page settings, and implementation of printing operations.
(1) generate printed documents
1. client script
Client scripts include VBScript, JavaScript, and JScript. The syntax used to develop applications in IE is JScript. Because it is almost identical with JavaScript, it can also be called JavaScript (hereinafter abbreviated as JS ). Generally, JavaScript is used to analyze Dom documents. Dom is a web document model proposed by Microsoft and is mainly used to implement web script programming.
Javascript can be used to analyze the content of the Source Page and extract the page elements to be printed for printing. By analyzing the content of the source document, you can generate a printed target document.
Advantage: the client generates the target document independently to reduce the server load;
Disadvantages: The analysis operations of the source document are complex, and the printed content in the source document must be agreed;
2. server-side program
The server-side program mainly uses the background code to read the print source from the database and generate the print target document. When the page is generated, you should also consider using CSS to implement forced paging control.
Advantage: You can generate a rich set of printed target documents, which is highly controllable. Since the printed content is obtained from the database, the generation operation is relatively simple;
Disadvantage: the server load is relatively large;
(2) page settings
Page settings mainly refer to setting the margins, headers, footers, and paper of printed documents. Page settings directly affect the generation of the printed document layout, so it is closely related to the generation of printed documents. For example, the number of rows, size, position, and font size of a table.
The existing technology is to use the built-in print template of ie6.0 to control page settings, which can have a great impact on printing the target document. The print template can control the page margins, headers, footers, and even pages, get user settings, and send settings to the server.
The print template technology allows you to customize the preview window and print format to maximize the impact on the target document and print effect.
(3) Implementation of print operations
This function is mainly implemented by using the webbrowser control function interface to print, print preview (default), page settings (default ).
<Object ID = 'webbrowser1' width = 0 Height = 0
Classid = 'clsid: 8856f961-340a-11d0-a96b-00c04fd705a2 '>
// Print
Webbrowser1.execwb (6, 1 );
// Print settings
Webbrowser1.execwb (8, 1 );
// Print and preview
Webbrowser1.execwb (7,1 );
Iii. Printing scheme used in this project
Call the server program method and print preview interface. For example, refer to the pageerrorprint. aspx. VB file in the project.
Main call page
Function printpage (ipageindex, strquery)
{
VaR strurl;
Strurl = "pageerrorprint. aspx? Pageindex = "+ ipageindex +" & querystring = "+ strquery;
Winprint = Window. Open (strurl, "", "Left = 2000, Top = 2000, fullscreen = 3 ");
}
Preview Control in HTML source of printed pages
<Script language = "JavaScript">
Document. Write ("<Object ID = 'webbrowser 'width = 0 Height = 0
Classid = 'clsid: 8856f961-340a-11d0-a96b-00c04fd705a2 '> </Object> ");
Webbrowser. execwb (7,1 );
Window. Opener = NULL;
Window. Close ();
</SCRIPT>
Program Header
'Declare the table container first
Protected withevents phcontainer as system. Web. UI. webcontrols. placeholder
'Number of records in each table
Private const itempertable as integer = 20
Key Implementation
'Create a table that meets printing requirements
Tabpageprint = newprinttable ()
'Add the header to this table
Call addtabletitle (tabpageprint)
'Initialize the recorder
I = 0
Iitemindex = istartpoint
For each clsitem in clsalldata. errorcollection
If I> 0 and I mod itempertable = 0 then
'Add a table control to the page.
Phcontainer. Controls. Add (tabpageprint)
'Add a line break to the page
Call addpagebreak ()
'Create a new round of table
Tabpageprint = newprinttable ()
Call addtabletitle (tabpageprint)
End if
'Add the record to the table
Call additemtotable (iitemindex, tabpageprint, clsitem)
Iitemindex = iitemindex + 1
I = I + 1
Next
'Add a table control to the page.
Phcontainer. Controls. Add (tabpageprint)
Supported Functions
'Function: add a line break for the page
Private sub addpagebreak ()
Dim ltbreak as literalcontrol
Ltbreak = new literalcontrol ("<P style = 'page-break-before: Always '> ")
Phcontainer. Controls. Add (ltbreak)
End sub
'Function: Create a table that meets printing requirements.
Private function newprinttable () as table
Dim tabsrc as new table ()
Tabsrc. width = unit. percentage (100)
Tabsrc. attributes ("border") = "1"
Tabsrc. cellpadding = 4
Tabsrc. cellspacing = 0
Tabsrc. borderwidth = unit. pixel (2)
Tabsrc. bordercolor = color. Black
Tabsrc. style. Add ("font-size", "12px ")
Newprinttable = tabsrc
End Function