General report printing for the processing scheme of Web printing

Source: Internet
Author: User

A lot of Web projects, most of the time when the content of the printed page, the use of the JavaScript call system built-in printing essentials to perform printing, that is, call PRINTCONTROL.EXECWB (?,?) Enables direct print and print preview functionality. The results and control of the printing is not very good, but it can be used reluctantly, to cope with the usual printing still can.
The code looks like this:

//call PRINTCONTROL.EXECWB (?,?) Enables direct print and print preview functionality. (print () Essentials printed directly with the system does not lurk in certain areas)//preview: Can you show previews? Null/false: Not displayed, true: DisplayfunctionPrintPage (preview) {Try{varContent=Window.document.body.innerHTML; varOricontent=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 configuration         if(preview==nullpreview==false) PRINTCONTROL.EXECWB (6,1); ElsePRINTCONTROL.EXECWB (7,1);//olecmdid_print=7; Olecmdexecopt_dontpromptuser=6/olecmdexecopt_promptuser=1Window.document.body.innerhtml=oricontent; }Catch(ex) {Alert ("Error executing JavaScript script. "); }}functionPrintconten (preview, HTML) {Try{varContent=html; varOricontent=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 configuration         if(preview==nullpreview==false) PRINTCONTROL.EXECWB (6,1); ElsePRINTCONTROL.EXECWB (7,1);//olecmdid_print=7; Olecmdexecopt_dontpromptuser=6/olecmdexecopt_promptuser=1Window.document.body.innerhtml=oricontent; }Catch(ex) {Alert ("Error executing JavaScript script. "); }} 

The above two functions are placed in a JS file, in the content of the page to apply the script file and call further encapsulated function to print the contents of the specified part:

<script language= "javascript" > function  Print (preview) {  var Tex            t = document.getElementById ("Content"). InnerHTML;        Printconten (preview, text); }

The results of the printing are roughly as shown, and if the printed page is in the frames page, the option to print only selected frames is selected.

Use this kind of essentials, 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 a lot of content is, there must be defects, but overall, is also a better choice.
Later in the need to do some paperwork, this control can not be done, so there is a need for a point or a control, can be better than the advantages of the way to play the thing.
Inadvertently, found a better print control, support various formats of printing, as well as I care about the document Set playing function, powerful, the use is very basic, especially worthy of selection.
Related address of the control:
Control Download Home page:
Control Blog Selection:
With this control, the print effect of the normal report is as follows:

The above two reports are printed in the same print section of the HTML content, but the latter looks a bit better, and provides a complete configuration of the report function.
The code is roughly as follows.

<script language= "JavaScript" >functionPrint (preview) {varText = document.getElementById ("Content"). InnerHTML;        Printconten (preview, text); }</script> <script language= "javascript" src= "" ></script> <object id= "Lodop" classid= "CLSID: 2105c259-1e0c-4534-8141-a753534cb4ca "width=0 height=0> </object> <script language=" JavaScript ">varLodop = document.getElementById ("Lodop");//This line of statements is intended to fit the DTD specificationChecklodop (); </script> <script language= "javascript" type= "Text/javascript" >functionPreview () {//Print PreviewCreatelicensedata (); Lodop. Set_show_mode ("Preview_in_browse", 1); Lodop.        PREVIEW ();        }; functionSetup () {//Print Maintenance To adjust the position of the userCreatelicensedata (); Lodop.        Print_setup ();        }; functionDesign () {//Print design Developer configuration content and locationCreatelicensedata (); Lodop.        Print_design ();        }; functionCreatelicensedata () {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 resolved CSS to control the beautiful, so there are moments, we print some HTML, without these styles, then out of table format and font, may be changed, not very good-looking. Then you need to implement the HTML style configuration.

If the print content is configured with a style, then the interface effect is much better.

The code for configuring the style is shown below.

<script language= "javascript" type= "Text/javascript" >functionPreview () {//Print PreviewCreatelicensedata (); Lodop. Set_show_mode ("Preview_in_browse", 1); Lodop.        PREVIEW ();        }; functionCreatelicensedata () {Lodop. Print_init ("Application Processing Order"); varStrbodystyle = "<link type= ' text/css ' rel= ' stylesheet '/><style><!--table {border:1;background-color: #CBCBCC} td {Background-color: #FFFFFE; border:1;} th {background-color: #F1F1F3;p adding-left:5px;border:1}-->< /style> "; varstrformhtml = Strbodystyle + "<body>" + document.getElementById ("content"). InnerHTML + "</body>"; Lodop. Add_print_htm (20, 40, 610, 900, strformhtml); Lodop.        PREVIEW (); }</script>

The next article continues to elect the printing function of the document set.

Source: http://www.educity.cn/develop/1678911.html

General report printing for the processing scheme of Web printing

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.