Implement general web report printing (Favorites) with XML

zhaozj2021-02-16  101

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:

true A4 210 297 0 0 0 0 latest transaction contract information Tabulation time: "Y =" 100 "fontname =" "" Y = "100" FontName = " Song "FontSize =" 12 "fontcolor =" black "b =" true "i =" false "u =" true "> unit: element

contract number Product name <

Td width = "50" align = "center" fontname = "Song" fontsize = "12" fontcolor = "black" b = "true" i = "false" u = "false" bgcolor = "white"> transaction volume < / TD>

Transaction price Transaction amount Harmoned amount starting price seller buyer <

/ TR>

20021010015 cnr 93 6680 621240 93 6680 Hubei Province State New Star Tractor Factory Zhonghua International Trade Co., Ltd. ......... Note:

a) If the server script dynamically generates an XML document, the sending content type should be set to Text / XML (the normal HTML page is TEXT / HTML), and the character encoding should be UTF-8, otherwise the encoding error problem will occur.

b) The file should be generated in strict accordance with the format specified in XML, otherwise the XML parser will not be parsed.

2. Client

You can use any application to read the XML file generated by the server. If you use the desktop application software development tools such as VB, Delphi, you can use the MSXML COM parser. It is recommended to use .NET, the interior has integrated XML parser, which can be used directly by using the .NET class library. You can make both desktop applications, via remote calls; can also be embedded in the IE browser, running directly on the web page.

Example diagram

Printing preview

Precautions:

1. If you use .NET, the client must install the .NET Framework1.0 running environment, download the address:

Http://download.microsoft.com/download/.netframesdk/redist/1.0/w98nt42kmexp/en-us/dotnetredist.exe

2. If you use the form embedded in the web page, then this program needs to be compiled into a control form (an extension DLL file), then insert the following tag in the web page:

Embed controls into a static or dynamic web page. The control file is then copied to the same directory as the web page (the control file name generated in the tag, which is namedpace name for this control).

to sum up

Ok, the article is basically completed here. Maybe someone will feel strange, you haven't cleared how to write specific print code. In fact, this article is just a solution about Web report printing. As mentioned above, how to achieve the client's printing has many choices, and then go deep into the scope of this article. I hope this article can play a role in pouring bricks and can provide a problem for everyone. Of course, if you want to get this source code, please contact me: nluyan@163.net, thank you.

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

New Post(0)
CopyRight © 2020 All Rights Reserved
Processed: 0.054, SQL: 9