Column
Using XML to implement universal web report printing
Lu Yan
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.
Substancy and safety
Scalability
Since the XML standard data format is used as an intermediate data exchange, this solution has very good scalability, for example, the client's .NET control can be directly replaced by Java Applet, ActivX or VB, VC, etc. . The server can also be arbitrarily selected by IIS or APACHE and other web servers. A database can also be used in any database. Includes SQL Server, Oracle or Access, etc.. This above has already talked, because the length of the article does not make the T-shirt that is given to me, and then emphasizes it just to deepen the readers' cross-platform understanding of XML. :)safety
Since the normal web server transmits data, it can be directly adopted by SSL security sockets and other already mature web encryption techniques. At the same time, XML can be encrypted on the data algorithm, and decrypt the client to ensure the security of the transmission.
Since the 80-port is used, it is not necessary to add another new dedicated port, which reduces the possibility of security vulnerabilities, and it can easily pass the network firewall and other protective equipment for both parties.
Program design
Format definition
In order to control the format of printing, we define the following format tags, which refer to HTML naming methods, so it is basically familiar with HTML to see the specific meaning of the label. If you think that these tags have not strong enough, you can also define some more and more precise format tags.
Main label description:
TEXT: Text string
Attributes:
x: Print the X coordinate
Y: print output Y coordinate
FontName: Font
FONTSIZE: Font size
FontColor: Color
B: Is it bold?
i: Is it behind it?
u: Whether there is an underscore
Table: Table
Attributes:
x: Print the X coordinate
Y: print output Y coordinate
Border: Border is thick
Bordercolor: Border color
Maxlines: Maximum number of lines per page
Tr: line
Attributes:
HEIGHT: Height
TD: column
Attributes:
Width: Width
Align: alignment
FontName: Font
FONTSIZE: Font size
Fontcolor: Font Color
B: Whether bold
i: whether it is behind
u: Whether to underside
BGCOLOR: background color
Next: Next
TableHead: head
Tablebody: entry
TABLEFOOT:
Page: Page Settings
Printward: horizontal / portrait print
PageType: Paper Type
PageLeft: left margins
PAGERIGHT: Right margins
PageTop: on the upper margin
Pagebottom: Backers
Label application example: