Alternative methods of Web Printing _ Experience Exchange

Source: Internet
Author: User
Tags print format
Alternative methods of Web printing choose from Wfmazhenhai Blog
Alternative methods for keyword Web printing
Source
I believe that the use of B/s way to do the application of the people may encounter such a problem, how to easily and beautifully realize the print report. If you use the browser's print menu to print, you will put some useless things on the page on the report, such as the Application menu. Because selecting a print menu to print a Web page will print out all the content in the page, and if your application has a split frame, the printed content will include the contents of each frame, and what you actually want is only part of it.  So there are many applications can only put the printing function in the background to complete. What should we do in the light of this situation? In fact, there are many ways to achieve the Web page printing function.
One way is to use professional printing tools, such as Crystal Reports (Crystal Report). Friends with Visual Studio 5.0 certainly remember this tool, but the version was only 4. Now the latest version has reached 9, nearly several versions of the Crystal Report Support Web printing. The simplest way is to use the Crystal Report to make a good template, and then use the ASP with parameters to call the production template can be. Crystal Report When you generate a report on a Web page, you can print it directly, or you can dump it as a different comparison through a file such as an Excel file. Use Crystal Report can make a very beautiful style, the key in your Crystal Report development ability, but because the Crystal report price is high, only when the project is very profitable to buy.
The second way is to buy a third party's online print control, the cost is cheaper than the Crystal report, but the effect of how the performance of the beholder.
The third approach is to use style sheets and JavaScript custom functions to implement. Through the style sheet and JavaScript, the implementation of Web page printing, the effect is also OK. Here is an example to invite you to take a look. The following is a detailed print function implementation:
<script language= "JavaScript" type= "Text/javascript"
!--
function DP () {
if (window.print)
{
var Div1 = Document.all.Div1.innerHTML;
var Div2 = Document.all.Div2.innerHTML;
// *****************************************************
DIV1, Div2 is for you in the printed area
This is based on what you want to print, from the original display page
<div id=div1>div1 ..... </div> <div Id=div2>div2 ... </div>
And so on, how many items will be printed?
var css = ' <style type= ' text/css ' media=all> ' +
' P {line-height:120%} ' +
'. ftitle {line-height:120%; font-size:18px; color: #000000} ' +
' TD {font-size:10px; color: #000000} ' +
' </style> ';
// *****************************************************
Define the CSS for printing, specifically what format you want to print out look at yourself
, but be aware that if there is anything inconsistent with the page here, it may print
The page format and font may be different
// *****************************************************
var body = ' <table width= "640" border= "0" cellspacing= "0" cellpadding= "5" > "+
' <tr> ' +
' <td class= ' fbody ' +
' <div align= ' center ' class=ftitle> ' + Div1 + ' </div> ' + Div2 +
' </td> ' +
' </tr> ' +
' </table> ';
// ******************************************************
To reset the print format here, according to your printing requirements, the original displayed
The div content of the page regroup, can according to your original form content, remove
Do not print, you can also be able to define the following noprint ignore you don't want to fight
Printing something that only calls what you want to print, but such a neglected place will
Print out empty, not very beautiful. Table width to match the printed paper width.
// ******************************************************
Document.body.innerHTML = ' <center> ' + CSS + body + ' </center> ';
// ******************************************************
Reset Document.body, Print document ready
// ******************************************************
Window.print ();
Window.history.go (0);
// ******************************************************
Invokes the print command to print the contents of the current window. When you print it is actually a new
Web page, but the page file is still original. Immediately after the call
Window.history.go (0), and then back to the page before the printing, the effect is quite poor
// ******************************************************
}
}
-->
</script>
<style>
@media Print {
. noprint {Display:none}
}
</style>
!--//.noprint defines noprint, class= "noprint" is added to the following areas where no printing is required, and window.print () is ignored when you print the-->
All right, all right, now all you have to do is call the DP function, if you design the button that implements the call on the same page, call it directly; if you use the frame method and the button that implements the call is on another page, the Window.focus () command is added to the first line of the DP function. Otherwise, only pages with buttons are printed.
The fourth approach, implementation is a tricky approach. The same is done by calling Window.print (), just creating a Web page of what you want to print, and the Print button on another frame. Assuming that the report page is on the mainframe, the button is on the Topframe, the button calls the Printreports () function, and the Printreports () function is the following to achieve the print job.
function printreports ()//topframe functions in Web pages
{
Try
// *******************************************************
Error handling, if the Web page in mainframe does not have a DP function then does not print
// *******************************************************
{
Window.parent.frames ("MainFrame"). DP ();
}
catch (E)
{
Alert ("No object to print!");
}
}
function DP ()//mainframe functions in Web pages
{
Window.focus ();
if (window.print)
{
Window.print ();
}
}
I personally think this is the most convenient way.
Finally, if you remove the "header, page Corner" setting in IE's "file-page Setup", the effect is better. Reproduced

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.