Using XML to implement universal web report printing (1)

xiaoxiao2021-03-06  81

The most headache of the application of the B / S structure can be that the report prints, since the browser can only be interacting as the user interface, so you cannot accurately control the client's printer. And many B / S structures often need to complete a very complex report print job. The page printing function that comes with IE can generally not meet the needs.

Crystal Report is a commonly used and recommended solution, but if we only need some small-scale report printing, Crystal Report is huge, and customizable is not very good, its print In fact, the print function of IE is also used, and the printing effect cannot be accurately controlled, and you need to register it.

So we discussed another way, simply, if you have any of the following needs, you can try this solution.

Solution applicability

1. Remote data printing. The data that needs to be printed is not locally, and remote read must be performed.

2. Precisely control the printing effect, including page format, pagination, additional entry, table, and more.

3. For security considerations, you cannot connect directly to the database.

Program principle

In fact, the principle is simple. Through XML powerful custom features, we can easily customize all our needs of the format control tags. After performing dynamic encoding on the server, pass the web server to the client, then format on the client. Analysis, directly control the printer print out the report we need from the client according to the server-side defined print format.

Technology choice

Since the report print is more complicated, in order to accurately control the print format, the report print job can not be used in a way of printing on the web browser page, and can only take the print job of the self-programming control client. Since the .NET Framework's WinForm can be embedded directly into the web page, we have this technology here, but please note that I don't mean that .NET WinForm is the only choice, in fact, you can use any client instead of it, for example Java Applet or ActiveX, even a normal application can be row.

Do not allow direct connection to the database, so you can only use the XML file to perform the intermediate data exchange format, and data transmission is performed by the default 80 port of the ordinary web server. In fact, I can't find other ideal programs. Of course, Web Service may be a kind, but it uses SOAP transmission data. From the principle, the XML should be used as the same type technology.

Address, I have to use the controlled components written by .NET, the advantage is:

1. It does not need to be registered with client. A big advantage is relative to ActiveX.

2. Highly higher security than ActiveX. Run under the control of .NET Common Language Runtime

3. Convenient to write. I like C # and Visual Studio .NET.

4. There is a very powerful print control. Use the .NET Framework class library.

5. Supports XML technology directly.

6. He is high in IE compatibility. The same is Microsoft products.

In addition, it is important to note that the default security level in .NET Framework SP1 and SP2 cannot run the controlled component directly, but in the .NET Framework 1.1 beta, it can be running directly.

Server-side You can use an existing server system and database, which does not require newly adding any new hardware devices and new .NET server managers, they are often important guys who take high salary. :)

The server's workflow is:

1. Accept the client's standard XML template query.

2. The database data format is required to convert the database data format into a standard XML data format according to the query requirements.

3. Send XML data through the 80 port.

Feasibility Analysis

Since most databases support data query and conversion in XML format, such as SQL Server 2000, Oracle 9i, IBM DB2 and other large-type relational databases. Just use simple settings to perform XML data conversion work. If the database cannot support direct XML data conversion, you can use some server-side scripts to convert work, such as JSP, ASP, PHP, and more. The client does not require any special settings, just install a .NET Framework distribution package with a size of 21m, and then open the web page to work. There is also no operating system restriction, it can support it from Windows 98 to Windows XP.

转载请注明原文地址:https://www.9cbs.com/read-122897.html

New Post(0)