Web Printing Series Tutorial II--using IE's print function for general web page printing

Source: Internet
Author: User
Tags change settings

When we are doing web development, we usually need to use print, however, due to web technology limitations and security concerns, the Web printing function has been very weak, so we can only accept. Perhaps in the development process you will often meet the customer said to you, "your system printing is too bad, you see Excel print how good Ah,", in the face of such users, we in addition to a wry smile, what can be said. If you explain to them what is the BS architecture, what is the CS architecture, not only can not solve the problem, but will incur the user's disgust.

So, are we not going to be able to do anything about it? The answer is, of course, negative. With the existing web technology, coupled with the flexible implementation of the request, we can also make a beautiful print out.

In the next few articles, I'll introduce several methods or techniques of printing separately. Some of these methods are simple, some are slightly more complicated. We still start from the basics, first understand the simplest printing technology, and then one step further improve, which is also conducive to digestion technology.

This article describes the use of IE provided by the simple printing function, to print the settings and print.

In IE, we can use JavaScript to invoke the Window.print () function implementation.   The following is a simple code example. <input type= ' button ' value= ' print ' onclick= ' javascript:window.print () '/>

When you click "Print", you can eject the Print window, as shown below.

Picture 1

With this function, you can achieve the simplest printing function. If we want to set the paper, margin, how to do it. We know that we can easily change the page margins, header and footer settings, and the default Internet Explorer printer through the Internet Explorer user interface, IE also provides a call to WebBrowser control to call, You can bring up the Print Settings window on the page, where the user can change the margins, header and footer settings, and so on. (However, there is no way to programmatically change these settings under Internet Explorer or WebBrowser controls.) In the third installment of this series, I'll explain how to programmatically change settings on a page.   We can call the WebBrowser control by entering the following code on the page. <object classid= "CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" ID=WB name=wb ></OBJECT> <input ' bu Tton ' value= ' prints ' onclick= ' JAVASCRIPT:WB. EXECWB (6,1) '/> <input type= ' button ' value= ' Print preview ' onclick= ' JAVASCRIPT:WB. EXECWB (7,1) '/> <input type= ' button ' value= ' page settings ' onclick= ' JAVASCRIPT:WB. EXECWB (8,1) '/>

The object in the example above is the print control provided by IE, called WebBrowser, which we can refer to in our Web page with the ID or name we set.
This object has a very good use, which involves printing on the following three items.
Wb. EXECWB (6,1) printing
Wb. EXECWB (7,1) Print preview
Wb. EXECWB (8,1) print Page Setup

Click the "Print" button to eject the same window as the Window.print () function. Click Print Preview to preview the current page.
Picture 2

Click "Page Settings", you can pop-up Page Setup window, in the Settings window, you can set the margins, headers and so on detailed settings.
Picture 3

Through the above three functions, we can be simple to print and set up, for the general printing requirements are basically enough.

What you need to note here is that the individual values in Page setup are stored in the user's registry.

The following is how Microsoft Internet Explorer accesses print settings:

For page margins, Microsoft Internet Explorer first tries to get the value from the following registry key: HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\PageSetup

If this is not the case, Internet Explorer will create this by copying values from the following registry key: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\PageSetup

If there is no such item, the default value is provided.

For headers and footers, the values are obtained from the following items:
HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\PageSetup

If there is no such item, the default value is provided.

The default value for margin is 0.75,

For Internet Explorer default printers, the default values are provided from the following items:
HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\pagesetup\printer

Note that these values work on the entire system, affecting all instances of the current user's WebBrowser control and Internet Explorer. Therefore, if you set the first page header to be "ajava.org", then the second page header is also it.

So, is there a way to set these options in a program without requiring the user to manually set them every time? See "[Ajava original]web Printing series three--the complex Web Printing setup Programmatically "

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.