Several scenarios for Web printing

Source: Internet
Author: User
Tags change settings html page requires ticket

Rotate from: http://elf8848.iteye.com/blog/626790

-------------------------------------------a web-based printing scheme comparison and analysis--------------------------------

The difficulty of web-based nesting is to accurately print the HTML rendered in the browser to the ticket, and to control the paging location. The following on the Internet Explorer can be used by the set of solutions, to a summary analysis, I hope to be helpful to everyone.

   first, the browser's Print function menu

The advantage of this approach is that there is no need to expand the browser, it is the simplest way, but the problem is the most, such as:

cannot be accurately paged. The browser is generally based on the user set page size, the content of the Web page, to decide the paging location, the programmer is difficult to control. There will be a footer header interference.

You cannot accurately align edge margins and print text.

Continuous printing cannot be resolved. For example, instead of printing just one ticket, you print several tickets in a row at a time.

   second, use WebBrowser control + JavaScript

This is actually a program call to the browser's Print function menu, which is no different from the Print function menu. The problem with paging is still there, but instead of having to go to a menu, a button in a webpage, or a link inside a page, can be called.

   third, using the print CSS

This is one of the most ideal ways to implement web sets. This approach enables the control of HTML document output printing by embedding print-related CSS styles in an HTML document, such as setting the paper size, paper orientation, print margins, paging, and so on. Obviously, this is a small cost, no need to download any plug-ins, and very good cross-platform. Print CSS has been going on for some time, but unfortunately, none of the vendors ' browsers have implemented these standards well so far, which makes it impossible for programmers to actually develop with print CSS. About printing CSS, see http://css-discuss.incutio.com/?page=PrintStylesheets

   iv. use of PDF files

In this way, a PDF file stream is downloaded from the server side, opened in IE with an Adobe plugin, and then printed with Adobe's print menu, although this option allows for precise nesting, but requires downloading of adobe plugins. This is a frequently recommended printing method for foreign reporting tools, but in China, where PDFs are less prevalent, this is not the best option.

   v. Use of pure ActiveX

The solution is to download a control where the data of the ticket is no longer rendered in HTML, but is rendered in ActiveX. The advantage of this scheme is the high precision of printing, good paging controllability, but the disadvantage is also obvious, embedded ActiveX control to destroy the Web app's overall HTML style, and such a control is larger (generally more than 1M), download time). This is generally the case with non-Java-class reporting products on the market.

   Vi. Adoption of the applet approach

The use of applets, paging or precise printing, can be perfect, but the shortcomings are also obvious, manifested in:

Installing applets costs a lot. Need to download a more than 10 m file.

When you print a report, you need to re-retrieve the data to the server with low efficiency. Because the applet scheme, generally HTML rendering data, the applet must be printed to the server to retrieve the same ticket data, it appears that the current page is printed on the ticket, in fact, the applet will not be used in the current HTML page data to print, Instead, download the data into the applet to print to the server. That is, to print, it must be two requests, one HTML rendering, one for printing.

Continuous printing cannot be resolved. For example, instead of printing just one ticket, you print several tickets in a row at a time.

does not resolve printer setup issues, such as when multiple printers are present, you always need to manually select which printer to print to.

On the market Java class reporting tools, generally recommended applet way to achieve printing.

   Seven, the lightweight way of ActiveX printing
-----SCRIPTX-----
ScriptX's free version is good enough to satisfy most of the needs.
There are two ways to use the Meadco ' s scriptx control, one is to use it for the free version, one for the premium version, the less for the free version, but the most important is the most commonly used page setup, which is still available, so use the free version. However, these two versions use the same CAB file, but there are some differences in the code settings.

-----Pazu (Quartet)-----
Pazu personal or commercial use is truly free, with no IP or domain name restrictions.

Pazu since June 2009, the use of free license, you must have a certain IP address or domain name (hostname), Pazu is bound IP or domain name, IP or domain name has not been determined we can not issue authorization, in addition, authorization once issued can not modify the binding. The IP and domain name of the binding must be the end user, so the end user's app site must be linked to the 4Fang site, otherwise Pazu will not work properly because it cannot verify the validity of the authorization (except for intranet applications).

Enterprises can purchase development integration version (suitable for project integration or product development company, provide keygen tools, generate license for themselves, do not restrict distribution)


-----Jatoolsprinter (Jay. Print control)-----
The free version can only be used in the 192.168.*** network segment, the version prior to 2.0 has a free version, and after 2.0 is charged. The latest version is 4.2. They can choose the output printer, paper size, print direction, etc. via web script, without having to manually set it each time.

Price please see: http://www.jatools.com/print/howtobuy.htm



For simple printing, we use the function of IE, for complex settings, it is recommended to use a lightweight way of ActiveX printing. In the next series of tutorials, we'll cover them all.



---------------------------------------two uses the IE printing function to carry on the general web page printing-----------------------------

When we do web development, we usually need to print, however, due to the limitations of web technology and security concerns, Web printing has been very weak, so we can only accept. Perhaps you in the development process often meet the customer to you, said, "Your system printing is too poor, you look at Excel printing how good Ah,", in the face of such users, we have nothing but a wry smile, what can we say. If you explain to them what is a BS architecture, what is CS architecture, not only can not solve the problem, but will incur users ' antipathy.

So, are we just not going to do anything? 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 will describe 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 step by step to improve, it is also conducive to digestion technology.

This article describes the use of IE provides simple printing functions, print settings and printing.

In IE, we can use JavaScript to invoke the Window.print () function implementation. The following is a simple code example.

Java code <input type= ' button ' value= ' print ' onclick= ' javascript:window.print () '/>[Java]View Plain copy print? <input type= ' button ' value= ' print ' onclick= ' javascript:window.print () '/>

<input type= ' button ' value= ' print ' onclick= ' javascript:window.print () '/>
  


Click "Print" to eject the print window, as shown below


With this function, the simplest printing function can be achieved. What to do if we want to set the page margins for the paper. We know that we can easily change margins, header and footer settings, and default Internet Explorer printers through the Internet Explorer user interface, IE also provides a call to WebBrowser control that we call, by calling, You can bring up the Print Settings window on the page, and in the Settings window, users 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 the WebBrowser control.) In the third chapter of this series, I'll show you how to programmatically change settings on a page. We can enter the following code on the page to invoke the WebBrowser control.
Java code <object classid= "CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" ID=WB name=wb ></OBJECT> &LT;INP UT type= ' button ' value= ' print ' onclick= ' JAVASCRIPT:WB. EXECWB (6,1) '/> <input type= ' button ' value= ' Print preview ' onclick= ' JAVASCRIPT:WB. EXECWB (7,1) '/> <input type= ' button ' value= ' page set ' onclick= ' JAVASCRIPT:WB. EXECWB (8,1) '/> [Java]View Plain copy print? <object classid= "CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" ID=WB name=wb ></OBJECT> <input ty Pe= ' button ' value= ' print ' onclick= ' JAVASCRIPT:WB. EXECWB (6,1) '/> <input type= ' button ' value= ' Print preview ' onclick= ' JAVASCRIPT:WB. EXECWB (7,1) '/> <input type= ' button ' value= ' page set ' onclick= ' JAVASCRIPT:WB. EXECWB (8,1) '/>
<object classid= "CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" ID=WB name=wb ></OBJECT> 

<input Typ E= ' button ' value= ' print ' onclick= ' JAVASCRIPT:WB. EXECWB (6,1) '/> 

<input type= ' button ' value= ' Print preview ' onclick= ' JAVASCRIPT:WB. EXECWB (7,1) '/> 

<input type= ' button ' value= ' page set ' 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 usage, which involves printing 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.


Click "Page Setup" to pop up the Page Setup window, in the Settings window, you can set the margin, header, etc. in detail.

With the above three functions, we can do simple printing and setup, for the general printing needs of basic enough.

It is necessary to note that the individual values in Page setup are stored in the user's registry.

Here's how Microsoft Internet Explorer accesses print settings:

For margins, Microsoft Internet Explorer first tries to get values from the following registry key:

Java Code hkey_current_usersoftwaremicrosoftinternet Explorerpagesetup [Java]View Plain copy print? Hkey_current_usersoftwaremicrosoftinternet Explorerpagesetup
Hkey_current_usersoftwaremicrosoftinternet Explorerpagesetup
   


Without this entry, Internet Explorer creates this key by copying values from the following registry key:

Java Code hkey_local_machinesoftwaremicrosoftinternet Explorerpagesetup [Java]View Plain copy print? Hkey_local_machinesoftwaremicrosoftinternet Explorerpagesetup
Hkey_local_machinesoftwaremicrosoftinternet Explorerpagesetup
   

If this item is not available, a default value is provided.

For headers and footers, the values are obtained from the following:
Java Code hkey_current_usersoftwaremicrosoftinternet Explorerpagesetup [Java]View Plain copy print? Hkey_current_usersoftwaremicrosoftinternet Explorerpagesetup
Hkey_current_usersoftwaremicrosoftinternet Explorerpagesetup

If this item is not available, a default value is provided.

The default value for margins is 0.75,

For Internet Explorer default printers, the default values are provided from the following:

Java Code hkey_current_usersoftwaremicrosoftinternet explorerpagesetupprinter [Java]View Plain copy print? Hkey_current_usersoftwaremicrosoftinternet Explorerpagesetupprinter

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

So, is there a way to set these options in the program without requiring the user to manually set them each time? Please look below.





------------------------------------three use Wscript.Shell to programmatically perform complex web printing settings-----------------------------

The previous article describes how to do simple printing and setup, suitable for printing with general printing requirements, such as Web sites on the Internet. However, when we develop the system for the Government or enterprise, the printing needs are more complex, the general printing Setup may not meet the needs of users, especially for the user good operability, can not require the user to print the printing manually, then, we need to implement in the program to print pre-set, Users just have to click to print.

So how do you implement a programmable print setup? There are a number of ways that this article will introduce Wscript.Shell to print settings.

With Wscript.Shell, client IE must be required to allow ActiveX interaction. If you are developing a system that is targeted at a specific user base, such as a government unit, or a business, then it is recommended that you ask your customers to add your system to a trusted site.

From the [Ajava original]web Print Series Tutorial II-using IE's printing function for general Web page printing, we know that margins, headers, footers are stored in the registry. So, next, we'll focus on the registry for programmable settings.

Take a look at the code below.

JavaScript code <title>ajava.orgweb Print Series Tutorials </title> <script language= "JavaScript" type= "Text/javascript"                >//define registry location var hkey_path= "HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\pagesetup\";       The value of name can be header (header), footer (footer), margin_bottom (bottom margin), Margin_left (left margin), Margin_right (right margin), Margin_top (top margin).         function PageSetup (name,value) {try {var wsh=new activexobject ("Wscript.Shell");         Wsh.regwrite (Hkey_path+name,value); Modify the registry value} catch (e) {alert (' requires running ActiveX to run to print settings.        '); }} </script> [JavaScript] View Plain copy print? <title>ajava.orgweb Print Series Tutorials </title>         <script language= " JavaScript "type=" Text/javascript ">         //define Registry location       &nbs p;  var hkey_path= "HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\pagesetup\";                //name values can be header (header), footer (footer), Margin_ Bottom (bottom margin), Margin_left (left margin), Margin_right (right margin), Margin_top (top margin).           //         function PageSetup (name,value) {         try {         var wsh=new activexobject ("Wscript.Shell") ;          wsh.regwrite (hkey_path+name,value);         //Modify registry values         }       &nbsp ;  catch (E) {         alert (' Run ActiveX is required to print settings. ';        }         }       &NBSP;&N  Bsp </script>   
<title>ajava.orgweb Print Series Tutorials </title> 

<script language= "JavaScript" type= "Text/javascript" > 
  //defines the registry location 

var hkey_path= "HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\pagesetup\"; 

//name values can be header (header), footer (footer), margin_bottom (bottom margin), Margin_left (left margin), Margin_right (right margin), Margin_   Top (top margin).     

// 

function PageSetup (name,value) { 

try { 

var wsh=new activexobject ("Wscript.Shell");     

Wsh.regwrite (Hkey_path+name,value);     

//Modify registry value 

} 

catch (E) { 

alert (' requires running ActiveX to run for Print setup.   ');     

} 

} 

</script>  

The above code is a simple function written in this word, it can be to header (header), footer (footer), margin_bottom (bottom margin), Margin_left (left margin), Margin_right (right margin), Margin_ Top (top margin) to set.

If you want to do this programmatically for a Web page that you want to print, you only need to call PageSetup. For example:

Java code <script language= "JavaScript" type= "Text/javascript" > PageSetup (' Header ', ' ajava.org ');         PageSetup (' footer ', ' ajava.orgweb print series tutorial '); </script> [Java]View Plain copy print?          <script language= "JavaScript" type= "Text/javascript" > PageSetup (' Header ', ' ajava.org ');           PageSetup (' footer ', ' ajava.orgweb print series tutorial '); </script>
<script language= "JavaScript" type= "Text/javascript" > 

PageSetup (' header ', ' ajava.org ');    

PageSetup (' footer ', ' ajava.orgweb print series tutorial '); 

</script>


If you do not add the site to a trusted site, a dialog box may pop up when you execute the above code. As follows.

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.