The effect and control of printing is not very good, but can also be used reluctantly, to deal with the general printing is OK.
The code looks like this:
Code
Copy Code code as follows:
Call PRINTCONTROL.EXECWB (?,?) Enables direct print and print preview. (Printing cannot hide certain areas directly with the system-supplied print () method)
Preview: Show preview. 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, (1,1) 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, (1,1) 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, in the page content by applying the script file and call the further encapsulated function can print the contents of the specified part:
Copy Code code 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 the following illustration, and if the printed page is in the frames page, you need to select the "Print only selected frame" option.
Using 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 trouble, especially for some report printing, need to output complex content is, but also a certain defect, but overall, is also a better choice.
Later in the need to do some paperwork, the control can not be done, so need a method or control, can better deal with the set of things.
Inadvertently, found a relatively good print control, support the printing of various formats, as well as I care about the card set playing function, powerful, use is very simple, very worthy of recommendation.
The associated address of the control:
Control Download http://www.jb51.net/codes/23956.html
Control Blog Introduction:http://blog.sina.com.cn/s/articlelist_1340389911_0_1.html
When you apply this control, the normal report prints as follows:
The above two reports are printed in the same format, and they are all part of the HTML content of the printed section, but the latter looks a little bit better and provides a perfect set of report functionality.
The code is roughly as follows.
Code
Copy Code code 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 intended 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 adjust position for user
Createlicensedata ();
Lodop. Print_setup ();
};
function design () {//Print designer Developer settings content and location
Createlicensedata ();
Lodop. Print_design ();
};
function Createlicensedata () {
Lodop. Print_init ("query Report");
Lodop. Add_print_htm (610, 900, 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 part of HTML, without these styles, then come out of the table format and font, may change, not too good-looking. Then you need to make 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
Copy Code code 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 processing list");
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 Ground-color: #F1F1F3;p adding-left:5px;border:1}--></style> ";
var strformhtml = Strbodystyle + "<body>" + document.getElementById ("content"). InnerHTML + "</body>";
Lodop. Add_print_htm (610, 900, strformhtml);
Lodop. PREVIEW ();
}
</script>