Http://www.blogjava.net/midstr/archive/2010/06/18/256597.html? Opt = Admin
Three implementation methods of web printing and web printing controls ZZ
Printing has always been a tough issue during management systems. The problem of B/S is even more prominent! The following are three common web printing methods:
1. Use Word or Excel to implement web printing. (If you do not modify the iesettings, you can generate an xls file on the Web server and then use xlbook = XLS. workbooks. open (remotepath) Get object printing)
Implementation process: first import the data to be printed to word or Excel, and then use the word or Excel printing function to implement web printing.
The following describes how to print an Excel file.
There are many ways to import data from webpages into excel. Here we will first introduce a method of using ActiveX control, that is, Excel. application, which is a programming interface provided by MS for excel. In many programming languages, you can use this interface to manipulate Excel tables.
The following is a simple example of using JavaScript scripts.
Function excelprint (){
VaR excelapp; // store Excel objects
VaR excelbook; // store the Excel worksheet File
VaR excelsheet; // Save the Excel worksheet
Try {
Excelapp = new activexobject ("Excel. application"); // create an Excel Object}
Catch (e ){
Alert ("enable ActiveX control settings! ");
Return ;}
Excelbook = excelapp. workbooks. Add (); // create an Excel Workbook File
Excelsheet = excelbook. activesheet; // activate an Excel worksheet
VaR rowlen = printtable. Rows. length; // number of rows of the table object
For (VAR I = 0; I
Note:
The premise for running this program is that IE must allow initialization and script running of ActiveX controls that are not marked as secure. The setting method is as follows:
Open Control Panel → Internet Options → Security → Custom Level → initialize and run scripts for ActiveX controls that are not marked as secure → select and enable them so that our programs can run. If this ActiveX Control setting is not enabled, an exception is thrown when the program executes the creation of an Excel object. In this case, you can catch this exception through the catch () Statement and handle it accordingly.
MS Excel must be installed on the client to run the program. Otherwise, the ActiveX driver cannot be used.
2. web printing using the browser's built-in printing Control
Implementation process: directly call the print function of IE or call window in the program. print () to implement web printing. The header and footer contain the webpage title, page number, URL, date, and other information. If you do not need this information, how can we remove it. The practice is actually very simple. You only need to open the page number Setting Dialog Box in the File menu of IE and remove the information set in the header and footer. However, each client needs to be set manually once. If you do not want each client to be manually set once, you can also use the code to modify the registry key value.
The process of modifying the registry is as follows:
Dim path, Reg
'Path stores the Registry address set for IE printing, and Reg stores the objects of the wscript. Shell component.
Path = "HKEY_CURRENT_USER/software/micro-soft/Internet Explorer/pagesetup"
'Modify the print settings through the registry, and only modify the values of the header, footer, and each boundary.
'Parameter Description: Header -- header, footer -- footer, margin_left -- left boundary
'Margin _ top -- upper boundary, margin_right -- right boundary, margin_bottom -- lower boundary
'In the margin settings, 1 corresponds to 25.4mm, that is, margin_left = 1 indicates 25.4mm of the actual value.
Function pagesetup (header, footer, margin_left, margin_top, margin_right, margin_bottom)
On Error resume next
Set Reg = Createobject ("wscript. Shell ")
If err. Number> 0 then
Msgbox "cannot create wscript. Shell object! "
Exit Function
End if
Reg. regwrite path + "/Header", header' sets the header
Reg. regwrite path + "/footer", footer 'sets the footer
Reg. regwrite path + "/margin_left", margin_left 'sets the left boundary.
Reg. regwrite path + "/margin_top", margin_top 'sets the upper boundary.
Reg. regwrite path + "/margin_right", margin_right 'sets the right boundary.
Reg. regwrite path + "/margin_bottom", margin_bottom 'sets the bottom boundary
End Function
Another thing to note is that the Print dialog box is directly displayed, rather than the preview window, by using the window. Print () method. Generally, you want to print and preview before printing. Or some formats are fixed. Each time they are in the same format, you want to print them directly without the pop-up dialog box.
Some users want to bind each print directly to a type of paper, and call that type of paper to print it directly during printing, So window. Print () is obviously far from enough.
3. web printing using third-party controls or report software
Implementation process: third-party controls encapsulate printed parameters and methods into objects and can be conveniently called directly on the page. For example, scriptx. Cab and eprint. Cab are all such controls. You can directly use code to set the Web Print header and footer, bind the web printing paper, set the web printing margin, print and preview the web, and print the Web directly.
Web Printing format settings, web printing pages, web printing pages re-print some information, some information can only be printed on the first page, some information can only be printed on the last page, and so on, are all solutions. Scriptx does not deal with these solutions. webprint has two solutions: webgrid and eprint. The table Type of row and column rules can be simply processed by webgrid, and the format of complex formats can be designed by eprint.
Generally, this type of printing control requires fees. You can consider it economically.
========================================================== ========================================================== ======================================
I. menu of the browser printing function
The advantage of this solution is that you do not need to expand the browser. It is the simplest method, but there are also the most problems, such:
1. Exact paging is not allowed.
Browsers generally determine the page size and content of web pages based on the page size set by users. It is difficult for programmers to control the page location from the rows. There will be footer header interference.
2. Incorrect padding and text printing.
3. continuous printing cannot be solved.
For example, instead of printing only one bill, several bills are printed consecutively.
Ii. Use webbrowser Control + Javascript
This is actually a program call of the browser printing function menu, which is no different from the printing function menu. The paging problem still exists, except that you can directly call a button or link on the webpage without clicking the menu.
3. Use print CSS
This is an ideal way to implement Web attacks. This method controls the output and printing of HTML documents by embedding printed CSS styles in HTML documents, such as setting the paper size, paper aspect direction, printing margin, and paging. Obviously, this method is low in cost and does not require any plug-ins to be downloaded, and it is very cross-platform. Print CSS has been launched for some time, but unfortunately, no vendor's browser has implemented these standards well so far, which makes it impossible for programmers to use print CSS for actual development. For more information about Printing CSS, see:
Http://css-discuss.incutio.com /? Page = printstylesheets
4. Use PDF files
In this way, you can download a PDF file stream from the server, open it with the Adobe plug-in IE, and then print it with the Adobe print menu. Although this solution can also achieve accurate nesting, however, you need to download the Adobe plug-in. This is a printing method that is often recommended by foreign reporting tools, but in China, where PDF is not so popular, this solution is not the best choice.
5. Use ActiveX only
This solution downloads a control, and the data of the ticket is not displayed in HTML format, but in ActiveX. The advantage of this scheme is that the printing accuracy is high and the paging controllability is good, but the disadvantage is obvious. Embedding ActiveX controls destroys the overall HTML style of Web applications, and such a control is relatively large (generally more than 1 m, download time is quite expensive ). This solution is generally used for non-Java report products on the market.
Vi. Using Applet
The use of Applet, paging or accurate printing, can be done perfectly, but the disadvantage is also very obvious, manifested in:
1. The cost of installing the applet is huge. You need to download files of dozens of MB.
The applet itself may not be large, but the JRE required to run the applet is generally at least 10 MB (jre1.4.2, 15.45 MB ). The user needs a lot of patience to print.
2. When printing a report, you need to retrieve data from the server again, which is less efficient.
Because of the applet scheme, data is usually presented in HTML mode. When printing, the applet must retrieve the data of the same ticket from the server. It seems that the bill on the current page is printed. In fact, the applet does not print the data on the current HTML page at all, but downloads the data from the server to the applet for printing. That is to say, for printing, two requests must be requested, HTML Rendering at a time, and printing at a time.
Java reporting tools on the market. Generally, the applet method is recommended for printing.
VII. Lightweight ActiveX Printing
This is one of the most creative web-based solutions released by the company at the customer's requirements.
As a Java-only report tool, Jade table is based on applet, and Applet is as small as possible (only 24 KB), but users still complain, because the JRE is too large, installation requires patience. In addition, using the applet method, it is difficult to implement the client's batch printing function.
We use a lightweight ActiveX printing solution to solve the customer's problems. The following is a typical example of this solution.
Posted on reading (8709) Comments (11) EDIT favorite category: JS
Feedback:
# Re: three implementation methods of web printing and web printing controls ZZ [not logged on]
| Poplar
Good. I have a long knowledge. Reply to more comments
# Re: three implementation methods of web printing and web printing controls ZZ
| Bgrs
Jatoolsprinter in China is doing well. Our project is in use. Print.jatools.com
Reply to more comments
# Re: three implementation methods of web printing and web printing controls ZZ
| Interdrp
Reyoprint (ruiyang. Print control) is a dedicated tool for implementing web page settings. As web application developers, we often encounter the need to print reports and bills in browsers. These requirements cannot meet the requirements of the browser's printing function, such as accurate printing, paging, and nesting. This requires a software tool that can solve common browser printing problems, which is also the development background of reyoprint. Reyoprint contains an ActiveX control (73 K) developed on vc7.0. This control controls printing parameters. reyoprint allows you to control pages, headers, footers, and margins through JavaScript scripts, print direction, custom paper, direct printing, pop-up Print dialog box and then print, preview, shrink printing, batch printing, nesting and other functions
Reyoprint has the following functions:
You can set printing parameters, paper type, and printing direction (horizontal or vertical.
Supports custom footer and header settings.
You can drag and drop a printing area or zoom in or out a scroll wheel.
Program paging and automatic paging are supported (ESC is supported to close the preview window ).
Supports print and preview. You can specify a page and a specified number of copies during preview.
You can directly print the URL of a specified ticket.
The basemap is only displayed during preview and not output to the printer.
Small, the entire control is only 73 KB, and no additional software packages are required.
It has nothing to do with the technical standards adopted by your project, and can be used by J2EE and. Net projects.
Applicable to IE 5.5 +.
Reyoprint has the following Disadvantages:
Since the control is based on webbroser, only Web Printing Based on IE is supported currently.
You cannot select a printer for direct printing. Reply to more comments
# Re: three implementation methods of web printing and web printing controls ZZ
| LLP
The demand for web printing is always changing, far more than this:
At first, people only want to complete the content of the webpage; then, they want to print content not including the header and footer; and then they want not to always pop up the Print dialog box to print multiple pages and pagination; later, I wanted to display the correct position. Later I wanted to adjust the position, save the adjusted content, and then I wanted to print the undisplayed content. Then I wanted to display the content, print is print; can print the content of multiple pages, can only print by address, can adapt to various browsers ..., in fact, the process of changing requirements involves the development of "Web browsing and viewing" to "Management System Interface. Why is lodop, a print control, so popular? Important! Developers must be able to meet the unknown needs of the control, so as not to waste the road. Reply to more comments
# Re: three implementation methods of web printing and web printing controls ZZ
| Find a beautiful girl as a wife
Good articles, favorites
Java paradise technology exchange, http://www.javaly.cn
2. Group number: 28840096. Reply to more comments.
# Re: three implementation methods of web printing and web printing controls ZZ
| Webprint
Beijing Fangcheng's printing plug-in is very good!
This is a very small ActiveX control that can be used after pages.
Set the page margin, header and footer, horizontal, vertical
Set custom paper, bind special paper to a specific report, and specify printer to print the report
Print the URL, print multiple documents at a time, and call back the event after printing is complete.
If you are interested, please refer to www.fcsoft.com.cn for more comments.
# Re: three implementation methods of web printing and web printing controls ZZ
| Preview 2010
If you can write a print control by yourself, you can reply to more comments.
# Re: three implementation methods of web printing and web printing controls ZZ
| Exezdl
Pazu -- 4 Fang web printing control is very good! Reply to more comments
# Eee
| E
Sdreee reply to more comments
# Re: three implementation methods of web printing and web printing controls ZZ
| Start
Eloon webprint is generated to meet the requirements of different users for printing Web documents. Considering the user's usage habits, the ideal printing format can be customized with simple operations, in addition, you can save the printed format as an XML Description document. When you enter this page the next time, the description document in this format is automatically loaded for printing.
Eloon webprint gives control of the printing format to the user, completely freeing software developers from developing and maintaining web printing, thus greatly accelerating the project development progress, saves development and maintenance costs for the company.
You can customize the following content:
1. Customize the default printer, print paper type, print direction, and margin.
2. Customize the printed header information.
3. Custom Print Title.
4. Customize the first information of the printed table.
5. Customize the output columns and column width, Data Alignment, data formatting, and project total control of the printed table.
6. Customize the end information of the printed table.
7. Customize the print footer information.
Chinese version. If you are interested, please refer to www.easywebprint.com.
Reply to more comments