Web Printing and web printing controls

Source: Internet
Author: User

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.Programming LanguageYou can use this interface to manipulate Excel tables.
The following is a simple example of using JavaScript scripts.
<Script language = "JavaScript">

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 <rowlen; I ++ ){

VaR Collen = printtable. Rows (I). cells. length; // Number of columns of the table object

For (var j = 0; j <Collen; j ++) // assign values to cells in an Excel table

Excelsheet. cells (I + 1, J + 1 ). value = printtable. rows (I ). cells (j ). innertext;} // import the innertext of each cell in the table to the cell in Excel.

Excelapp. Visible = true; // sets the EXCEL object to be visible}

Excelsheet. printout (); // print the worksheet

Excelbook. Close (true); // close the document

Excelapp. Quit (); // end an Excel Object

Excelapp = NULL; // release an Excel Object

 

</SCRIPT>

Note:
RunProgramThe premise is that IE should 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 () is used for 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 manually set once. You can also useCodeYou can modify the key value of the registry.
The process of modifying the registry is as follows:
<Script language = "VBScript">

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 border

Reg. regwrite path + "\ margin_bottom", margin_bottom 'sets the bottom boundary

End Function

</SCRIPT>

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 processed by a simple webgrid, and the complex format 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. The padding and text cannot be accurately aligned.
  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 large and small paper sizes, vertical and horizontal directions, and printing margins, 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 also 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. Actually, 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.

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.