Analysis of the related technology of web printing

Source: Internet
Author: User
Tags print format requires
Technical analysis of Web|web print Web printing

Existing Web Print control technology is divided into several schemes

Custom control finishes printing

Using IE self-webbrowser control to realize printing

Printing with third party controls

The following are mainly about the first two aspects of the content



One, custom control way

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. You can print on the client only if you download and register the generated components on the client computer.

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.



Second, 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: Table number of rows, size, position, size of the font 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);



Third, the project adopts the printing scheme

Server-side program mode, Print preview interface calls, for example, the main reference 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



' Function: Create a form that matches the print 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


Excerpt from CSDN forum



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.