Analysis of the related technology of WEB printing

Source: Internet
Author: User
Tags print format
Wen/Checon

The people who do the web development will face a common problem, that is, print. Indeed, there are limitations to the printing of Web applications relative to Windows desktop applications, and technicians often encounter such or such requirements in the course of project development. Desktop application developers will be very familiar with the Crystal Reports, Active reports, such as report controls, they have not only a simple and flexible design interface, but also has a very powerful report function, to meet the needs of a variety of reports printing. Web applications can only look for other solutions because of their special rendering methods. Now let's analyze the Web printing scheme that is now in shape:

Existing Web Print control technologies are divided into several scenarios:

A Custom control finishes printing
Using IE self-webbrowser control to realize printing
Printing with third party controls
1, custom control mode
Custom control way is to use VB or VC tools to generate COM components, with a defined print format to analyze the printing source files to achieve printing. Only the generated components are downloaded and registered on the client computer to implement the
Print.
The main difficulty is to define the print format and how to analyze the print source files. The best way to do this is to use XML technology to solve problems comprehensively, and XML makes it easy to define the format of text, tables, and so on that print the target.
But the development of the programmer requires high, difficult than the larger.
2, the use of WebBrowser to achieve web printing
WebBrowser is an IE-built browser control that requires no user downloads. This document discusses the WebBrowser control technical content for the IE6.0 version. Its related technical requirements are: the production of printed documents, page settings, printing operations, such as the implementation of several links.
(i), print the document generation
1. Client Script mode
Client script is divided into VBScript, JavaScript, and JScript scripting languages. The syntax used for developing applications under IE is JScript, which is almost indistinguishable from JavaScript, so it can also be called JavaScript (JS below). Generally, the main use of JS to achieve the analysis of DOM documents, Dom for Microsoft proposed a Web document model, mainly for the implementation of Web script programming.
The use of JS can analyze the content of the source page, will be printed on the page elements extracted to achieve printing. You can generate a print target document by analyzing the contents of the source document.
Advantages: The client completes the production of the printing target document independently and reduces the server load;
Disadvantages: The source document analysis operation is complex, and the source document print content to have the agreement;
2, server-side program mode
Server-side program mode, mainly using background code to read the print source from the database, to generate the print target document. When the page is generated, you should also consider using CSS to enforce paging control.
Advantages: can generate very rich content of the printing target document, the content of the target document is more controllable. Because the print content is obtained from the database, the generation operation is relatively simple;
Disadvantage: Server-side load is relatively large;
(b), page Setup
Page Setup is mainly about setting the margins, headers, footers, paper, and so on for the printed document. Page Setup will directly affect the production of printed document layout, so it is closely related to the generation of printed documents. For example: a table
Number of rows, size, position, font size, and so on.
The existing technology is to use the IE6.0 built-in print template to control page settings, which can have a very large impact on the printing of the target document. The Print Template Controls page margins, headers, footers, odd and even pages, and can get the user's settings and send settings to the server side.
Print template technology can customize the preview window and print format to maximize the impact of the target document and printing effect.
(iii), the implementation of printing operations
This feature is implemented primarily by using the function interface of the WebBrowser control to achieve print, Print preview (default),
Page Setup (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 Preview
WEBBROWSER1.EXECWB (7,1);
3, an example project to adopt the printing scheme
Server-side program mode, Print Preview interface call, for example, the main reference to the project:
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 the print page HTML source
<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 headers
' First declare the table container
Protected WithEvents Phcontainer as System.Web.UI.WebControls.PlaceHolder
' Number of records in each table
Private Const itempertable as Integer = 20
The key implementation part
' Create a form that meets the print requirements
Tabpageprint = Newprinttable ()
' Add a table header to this table
Call Addtabletitle (Tabpageprint)
' Initialize Logger
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 newline character to the page
Call Addpagebreak ()
' Create a new round of tables
Tabpageprint = Newprinttable ()
Call Addtabletitle (Tabpageprint)
End If
' Add a 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)
Support functions
' Function: Add line break for page
Private Sub Addpagebreak ()
Dim Ltbreak as LiteralControl
Ltbreak = New LiteralControl ("<p style= ' page-break-before:always ' >")
PHCONTAINER.CONTROLS.ADD (Ltbreak)
End Sub
Second, the use of IE itself printing
This way is relatively simple, but also commonly used printing methods, just want to report the page design, the user through the IE menu print function to complete the printing. The advantage is simple, easy to implement, the disadvantage is not flexible, can not control the paging, can not control the headers and footers.
Export the report as Word,excel or PDF print
This way you need to export the page as an Office document or PDF, and the minimum requirement is that the client has installed software to open Word, Excel, or PDF documents. This approach can be easily implemented through Crystal Report components or other Third-party controls. When exported to PDF, the print quality and effect are good, and users can customize the printed content and format after they are exported to Word or Excel.
In short, the existing printing scheme has its own strengths, in the development process should be based on the needs of users to choose, using IE simple to print, easy to implement, in the user needs simple or less print content in the case of the use of this scheme is more appropriate. Printing with custom controls enables full customization, but requires high technical requirements and development cycles. Using the export method can satisfy the user needs a little customization or print content has multiple pages of requirements.

(--partial excerpt from csdn.net)

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.