Technical Analysis on Web Printing

Source: Internet
Author: User
Tags print format
I. Custom Controls are printed
Print using the webbrowser control provided by IE
Printing using third-party controls
1. 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
Print.
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.
2. Use webbrowser for Web Printing
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 developed by Microsoft and 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.
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 );
3. The printing scheme adopted by an instance Project
The method of the server program and the print preview interface call are as follows:
Pageerrorprint. aspx. VB File
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
Ii. Use IE to print
This method is simple and commonly used for printing. You only need to design the report page and print it using the print function in the IE menu. The advantage is that it is simple and easy to implement. The disadvantage is that it is not flexible. It cannot control pages, but cannot control headers and footers.
3. Export the report to Word, Excel, or PDF
In this way, you need to export the page to an office document or PDF file. The lowest requirement is that the client has installed the software used to open Word, Excel, or PDF documents. This method can be easily implemented through the crystal report component or some other third-party controls. After being exported as PDF, the quality and effect of printing are good. After being exported as word or Excel, you can customize the printed content and format.
In short, the existing printing scheme has its own advantages. In the development process, it should be selected based on users' needs, and IE printing is simple and easy to implement, this solution is suitable when users have simple requirements or few printed content. Custom Control printing can be used to achieve full customization, but requires high technical requirements and development cycle. You can use the export method to customize or print multiple pages.

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.