How to Use the Asp.net print control

Source: Internet
Author: User

Although the print effect and control are not very good, but can barely use, to deal with general printing is still possible.
Code As follows:
Code Copy code The Code is as follows: // call printcontrol. execwb (?,?) Supports direct printing and print preview. (Print using the print () method provided by the system cannot hide some areas)
// Preview: whether to display the preview. Null/false: not displayed; true: Displayed
Function printpage (PreView)
{
Try
{
VaR contentmediaworkflow Doc ument. 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> ";
Too many Doc ument. Body. innerhtml = content;
// Printcontrol. execwb () print preview, () Open, () Save as, () Select All, () attribute, (6, 1) print, (6, 6) print directly, (8, 1) page settings
If (Preview = NULL | Preview = false) printcontrol. execwb (6, 1 );
Else printcontrol. execwb (7,1); // olecmdid_print = 7; olecmdexecopt_dontpromptuser = 6/olecmdexecopt_promptuser = 1
Too many Doc ument. Body. innerhtml = oricontent;
}
Catch (Ex) {alert ("An error occurred while executing the Javascript script. ");}
}
Function printconten (preview, HTML)
{
Try
{
VaR content = HTML;
VaR oricontentmediaworkflow Doc ument. 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> ";
Too many Doc ument. Body. innerhtml = content;
// Printcontrol. execwb () print preview, () Open, () Save as, () Select All, () attribute, (6, 1) print, (6, 6) print directly, (8, 1) page settings
If (Preview = NULL | Preview = false) printcontrol. execwb (6, 1 );
Else printcontrol. execwb (7,1); // olecmdid_print = 7; olecmdexecopt_dontpromptuser = 6/olecmdexecopt_promptuser = 1
Too many Doc ument. Body. innerhtml = oricontent;
}
Catch (Ex) {alert ("An error occurred while executing the Javascript script. ");}
}

The above two functions are placed in a JS file. You can print the content of the specified part by applying the script file and calling the further encapsulated function in the page content:Copy codeThe Code is as follows: <script language = "JavaScript">
Function print (PreView ){
VaR text = Document. getelementbyid ("content"). innerhtml;
Printconten (preview, text );
}

The print effect is roughly as shown in figure. If the printed page is on the frame page, you must select the "print only selected frame" option.

Using this method, you do not need to install any controls, and it has a good compatibility advantage. However, it seems that the report content is difficult to control, especially for some report printing, the output of complicated content is also flawed, but in general, it is also a good choice.

Later, I needed to do some work on the card set, so this control would not be able to do it. Therefore, I needed a method or control to better handle the problem.

Inadvertently, I found a good printing control that supports printing in various formats, as well as the card set playing function that I care about. It is powerful and easy to use and is highly recommended.

Controls:

Control download http://www.jb51.net/codes/23956.html

Control blog Introduction: http://blog.sina.com.cn/s/articlelist_1340389911_0_1.html

Apply this control. The print effect of a common report is as follows:

In fact, the printing of the preceding two reports is similar, both of which are HTML content. However, the latter looks better and provides comprehensive report function settings.

The code is roughly as follows.
Code

Copy code The Code is as follows: <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 used to comply with 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 adjust the location for the user
Createlicensedata ();
Lodop. print_setup ();
};
Function Design () {// print the content and location set by the design developer
Createlicensedata ();
Lodop. print_design ();
};
Function createlicensedata (){
Lodop. print_init ("query report ");
Lodop. add_print_htm (20, 40,610,900, document. All ("content"). innerhtml );
Lodop. Preview ();
}
</SCRIPT>

Most of the time, the content we don't have is controlled by CSS, so sometimes we print some HTML. If we don't have these styles, the table format and font come out, may change, not very nice. You need to set the HTML style.

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


The following code sets the style.
Code

Copy code The Code is as follows: <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 Form ");
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 {background-color: # f1f1f3; padding-left: 5px; Border: 1} --> </style> ";
VaR strformhtml = strbodystyle + "<body>" + document. getelementbyid ("content"). innerhtml + "</body> ";
Lodop. add_print_htm (20, 40,610,900, 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.