Asp.net web page printing III

Source: Internet
Author: User

Asp.net web page printing 1

Asp.net web page printing II

 

Some time ago I wrote two articles without third-party controls. I used pure JavaScript to solve the problem of Asp.net page printing. Some problems were found during the test: for example, the page is not very friendly, the border of each page is not set, the header and footer are not well handled, and the page margin is printed out incorrectly after it is set. After several days of further research, we finally solved all these problems, it can be said that the perfect Implementation of the page printing, data paging, paper size settings, margin settings, header and footer settings (haha oneself YY ).

I would like to share with you some of the main issues that have been solved.

Question:

1. Add a border for the page to add a div box to the outermost layer of the page after each page, so that the preview effect is better;

2. Reset the DIV nesting composition of each page; set the header, footer, page, and so on;

3. Set the paper size, margins, and other information during printing;

Solution:

1. adding a border Div for a page involves two issues. One is to dynamically generate a border for each page based on the number of pages after the page; the second is that the border cannot be printed and should be removed during printing. What should I do? -- My method is to set a <Div id = "pageborderdiv" class = "noprint" style = "position: absolute; "> </div> the child that dynamically adds the DIV after each paging, that is, the DIV layer of the border. This not only solves the problem of displaying borders, but also prevents these divs from being printed during printing.

2. Each page div is composed, as shown on the right. The size of the outermost div is the size of the printed paper. The height of the second div is the height of the paper, and the width is the size of the paper-the size of the left and right margins; then the height is divided into three parts, namely divided by the header, footer, and page.

3. Set the paper size, margins, and other information during printing. This is the most important part. Because everything I did was just a problem of display, and it was more important to print what I saw. The reason why I encountered a problem after setting the margin for printing is that I did not set the size of the page. Here, we can use CSS @ page to set the attributes of the printed page. @ Page

Here, the size is the size of the paper, and the margin is the margin, because our margins are set to the DIV of each page, so we can set the margin value here to 0 PX.

The demo has not been sorted out yet.

Recently, I have read articles about the hope demo. I have sorted it out and posted it here for your reference. The demo link is as follows:

ASP. netprintdemo

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.