Common Report printing _javascript tips for Web Printing solutions

Source: Internet
Author: User

Many Web projects have been done, most of which are printed on the page content, using JavaScript to call the system's built-in print method to print, that is, call PRINTCONTROL.EXECWB (?,?) Enables direct print and print preview. 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

Code highlighting produced by Actipro Codehighlighter (freeware) http://www. codehighlighter.com/-->//call PRINTCONTROL.EXECWB (?,?) Enables direct print and print preview. (The print () method printed directly with the system can not hide certain areas)//preview: Show preview. Null/false: Do not display, 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) direct printing, (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; The catch (ex) {alert ("Failed to execute a JavaScript script"). "); } function Printconten (preview, html) {try {var content=html; var oricontent=window.document.body.innerhtml; while con
Tent.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) direct printing, (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; The catch (ex) {alert ("Failed to execute a 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:

<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.

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

<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 user adjust position createlicensedata (); Lodop.
Print_setup ();
};
function design () {///Print designer 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 (); }
&Lt;/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

<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>

The above is a small set to introduce the Web Printing solution of the general report printing function, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

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.