Implementation of partial page printing by asp.net

Source: Internet
Author: User

Today, I am working on a contract signing table for a company. Their requirements need to be printed. So I searched a page for some printed code on the Internet and did not look at it at the beginning, get started directly.

Code:
<Script type = "text/javascript">
Function preview (preview)
{
If (then <10)
{
Bdhtml###doc ument. body. innerHTML; // obtain the html code of the current page
Sprnstr = "<! -- Startprint "+ print +" --> "; // you can specify the start area for printing.
Eprnstr = "<! -- Endprint "+ print +" --> "; // sets the print end area.
Prnhtml = bdhtml. substring (bdhtml. indexOf (sprnstr) + 18); // retrieves html from the start code

Prnhtml = prnhtml. substring (0, prnhtml. indexOf (eprnstr); // retrieves html from the end code
Too many Doc ument. body. innerHTML = prnhtml;
Window. print ();
Required parameter Doc ument. body. innerHTML = bdhtml;
}
Else
{
Window. print ();
}
}

However, I found that all the borders of the tables in the table could not be printed after I used them. I asked the Group experts for advice, the original background color and background image are not printed.

After modification, I wrote three classes with css to solve the problem. There was another problem in the test. The print in IE browser was no problem, but there was no table when I used partial printing, looking for bugs after a bit of depression

You can view the Page code to find out the difference between partial printing and full-page printing:

Observe the dig jscode repository Doc ument. body. innerHTML = prnhtml; the Code indicates that the code to be printed is obtained and assigned to the entire page code, but the code to be printed does not contain the body tag, therefore, the entire page is empty during local printing.

Modify as follows:

Function preview (preview)
{
If (then <10)
{
Bdhtml###doc ument. body. innerHTML; // obtain the html code of the current page
Sprnstr = "<! -- Startprint "+ print +" --> "; // you can specify the start area for printing.
Eprnstr = "<! -- Endprint "+ print +" --> "; // sets the print end area.
Prnhtml = bdhtml. substring (bdhtml. indexOf (sprnstr) + 18); // retrieves html from the start code

Prnhtml = prnhtml. substring (0, prnhtml. indexOf (eprnstr); // retrieves html from the end code
Required parameter Doc ument. body. innerHTML = "<body>" + prnhtml + "</body> ";
Window. print ();
Required parameter Doc ument. body. innerHTML = bdhtml;
}
Else
{
Window. print ();
}
}

The local print after adding the body is normal!

Source: blog

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.