Page Printing Technology Summary

Source: Internet
Author: User

I. Overview
For the application based on B/S architecture, the client page printing has been a headache, the simple way is: 1. Use IE printing function; 2. Use the Crystal Report. But the above two methods, have great limitations, it is difficult to achieve the special requirements of typesetting and accurate positioning, so can not meet the requirements of some special customers BT. To this end, I summed up my own experience in the use of Web printing, and you share.
This article covers the following techniques: JavaScript, ActiveX, asp.net, GDI +.

Two. Basic structure
First of all, we can't use IE's printing function, we must design the ' print ' button. Many people are accustomed to the ' print ' button on the page to be printed, in order not to print the button to print, the following methods: 1. Before printing the hidden button; 2. printing; 3. Display button.
I think this is more troublesome, so I use the framework. A total of three pages:
1.main.htm: frames page, above is the Print button, the following is the page to be displayed.
2.header.htm: Title bar, containing at least one print button.
3.report.aspx: The page to be printed, generated by the user.

Main.htm


<title></title>

<frameset rows= "10%,90%" frameborder= "0" border= "0" framespacing= "0" >
<frame id= "header" Name= "header" src= "header.htm" noresize scrolling= "no" >
<frame id= "" "Name=", "src=" report.aspx "noresize scrolling=" Auto ">
</frameset>


Header.htm


<script Id=clienteventhandlersjs language=javascript>
<!--
function Btnprint_onclick ()
{
Parent.report.focus ();
Parent.report.print ();
}
-->
</script>

<body>
<input id= "Btnprint" type= "button" value= "print" name= "print" onclick= "return Btnprint_onclick ()" >
</body>


In this way, when you click the ' Print ' button, the content of the Report.aspx page will be printed directly, both simple and intuitive.

Three. Print
To fully control printing, you must set the headers, footers, and margins by your program. Each client's IE settings are not the same, you can ask your customers to modify their print settings for the value you specify, obviously this is not realistic. So the right thing to do is:
1. Backup customer print page settings;
2. Set the header and footer up and down the left and right margin for their own needs;
3. Print;
4. Restore the original print page settings.
A control called ScriptX is used here. You need to download a file: smsx.cab, download address: http://www.meadroid.com/scriptx/sxdownload.asp. This address does not guarantee long-term validity, and you can search the search engine for ' scriptx ' to get more relevant information.

Add a reference to the control in "Header.htm":
<object id= "Factory" style= "Display:none" codebase= "http://localhost/WebApplication1/smsx.cab#VVersion=6,3,434,12"
Classid= "clsid:1663ed61-23eb-11d2-b92f-008048fdd814" viewastext>

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.