How to use ASP. NET print Control

Source: Internet
Author: User
The effect of printing and control, although not very good, but also can reluctantly use, to deal with the general printing or can be.
The code looks like this:
Code

Call PRINTCONTROL.EXECWB (?,?) Enables direct print and print preview functionality. (The print () method provided directly with the system does not hide certain areas)//preview: Whether a preview is displayed. Null/false: Not displayed, true: Display function PrintPage (preview) {try {var content=window.document.body.innerhtml; var oricontent= Content while (Content.indexof ("{$printhide}") >=0) Content=content.replace ("{$printhide}", "Style= ' Display:none '"); if (Content.indexof ("id=\" printcontrol\ "") <0) content=content+ "<object id=\" printcontrol\ "WIDTH=0 HEIGHT=0 Classid=\ "clsid:8856f961-340a-11d0-a96b-00c04fd705a2\" ></OBJECT> "; Window.document.body.innerhtml=content; PRINTCONTROL.EXECWB (7,1) Print Preview, (p) Open, (4,1) Save As, (17,1) Select All, (10,1) properties, (6,1) print, (6,6) print directly, (8,1) Page Setup if (preview==null| | Preview==false) PRINTCONTROL.EXECWB (6,1); else PRINTCONTROL.EXECWB (7,1); olecmdid_print=7; Olecmdexecopt_dontpromptuser=6/olecmdexecopt_promptuser=1 window.document.body.innerhtml=oricontent; } catch (ex) {alert ("Error executing JavaScript script. "); } } function Printconten (preview, html) {try {var content=html; var oricontent=window.document.body.innerhtml; while (Content.indexof ("{$printhide}") >=0) Content=content.replace ("{$printhide}", "Style= ' Display:none '"); if (Content.indexof ("id=\" printcontrol\ "") <0) content=content+ "<object id=\" printcontrol\ "WIDTH=0 HEIGHT=0 Classid=\ "clsid:8856f961-340a-11d0-a96b-00c04fd705a2\" ></OBJECT> "; Window.document.body.innerhtml=content; PRINTCONTROL.EXECWB (7,1) Print Preview, (p) Open, (4,1) Save As, (17,1) Select All, (10,1) properties, (6,1) print, (6,6) print directly, (8,1) Page Setup if (preview==null| | Preview==false) PRINTCONTROL.EXECWB (6,1); else PRINTCONTROL.EXECWB (7,1); olecmdid_print=7; Olecmdexecopt_dontpromptuser=6/olecmdexecopt_promptuser=1 window.document.body.innerhtml=oricontent; } catch (ex) {alert ("Error executing JavaScript script. "); } }

The above two functions are placed in a JS file, and the content of the specified part is printed in the page content by applying the script file and invoking further encapsulated functions:

<script language= "JavaScript" > function Print (preview) {var text = document.getElementById ("content"). InnerHTML ; Printconten (preview, text); }

The effect of printing is roughly as shown, and if the printed page is in a frames page, you need to select the option to print only selected frames.

Use this method, do not need to install any control, has a good compatibility advantage, but out of the report content, as if the control will be more troublesome, especially for some report printing, need to output complex content is, there are some defects, but overall, is also a better choice.

Later in the need to do some paperwork, this control can not be done, so need a method or control, can better deal with the situation of the set.

Inadvertently, found a better print control, support a variety of formats of printing, as well as I care about the document Set playing function, powerful, very simple to use, it is highly recommended.

To apply this control, the normal report prints as follows:

The above two reports are almost all printed in the HTML content of the print section, but the latter look a little bit better and provide a very good set of reporting features.

The code is roughly as follows.
Code

<script language= "JavaScript" > function Print (preview) {var text = document.getElementById ("content"). InnerHTML ; Printconten (preview, text); } </script> <script language= "javascript" src= "Http://www.cnblogs.com/Scripts/CheckActivX.js" ></ script> <object id= "Lodop" classid= "Clsid:2105c259-1e0c-4534-8141-a753534cb4ca" width=0 height=0> </ Object> <script language= "JavaScript" > var Lodop = document.getElementById ("Lodop"); This line of statements is to conform to the DTD specification Checklodop (); </script> <script language= "javascript" type= "Text/javascript" > Function Preview () {//Print preview Createlicensedata (); Lodop. Set_show_mode ("Preview_in_browse", 1); Lodop. PREVIEW (); }; function Setup () {//Print maintenance to user adjust position createlicensedata (); Lodop. Print_setup (); }; function design () {//Print design Developer settings content and location Createlicensedata (); Lodop. Print_design (); }; function Createlicensedata () {Lodop. Print_init ("query Report"); Lodop. Add_print_htm (610, document.all ("content"). InnerHTML); Lodop. PREVIEW (); } </script> 

Many times, we also do not have content, are through the CSS to control the beautiful, so sometimes, we print some HTML, without these styles, then out of table format and font, may change, not very good-looking. Then you need to make the HTML style settings.

If you set a style for the printed content, the interface is much better.

The code that sets the style is shown below.
Code

<script language= "JavaScript" type= "Text/javascript" > Function Preview () {//Print preview createlicensedata (); Lodop. Set_show_mode ("Preview_in_browse", 1); Lodop. PREVIEW (); }; function Createlicensedata () {Lodop. Print_init ("Application processing order"); var strbodystyle = "<link type= ' text/css ' rel= ' stylesheet ' href= ' http://www.cnblogs.com/Themes/Default/style.css ' /><style><!--Table {border:1;background-color: #CBCBCC} td {Background-color: #FFFFFE; border:1;} th {back Ground-color: #F1F1F3;p adding-left:5px;border:1}--></style> "; var strformhtml = Strbodystyle + "<body>" + document.getElementById ("content"). InnerHTML + "</body>"; Lodop. Add_print_htm (610, strformhtml); Lodop. PREVIEW (); } </script> 
Related Article

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.