|
Although HTML is great for formatting information on a page, when it comes
to printing, problems arise due to the absence of a page break facility. As
a result the printed HTML document contains information continually output over
multiple pages without any predetermined breaks. In addition, the point at
which a page ends and a new one begins is determined by the browser font
size, font type, printer type and printer driver. This is unfortunate as
ASP and HTML are two complimentary languages, capable of good database retrieval
and data formatting together.
In search of an alternative, I created a VB ActiveX DLL to modify a
Word template on the web server. The template was an empty formatted report, which was
subsequently populated from the results of a query. As many records
existed, the DLL was passed the unique key ID and the report was populated
with the relevant data. Again, more problems arose, as the DLL required a
reference to the MS Word Object Library, which in turn requires an
instance of WinWord to be loaded into memory on the web server. Under
periods of heavy user activity, the overhead of multiple instances of
WinWord, at 8.5Mb a piece, began to effect web server performance.
The easiest and most efficient solution was to use RTF files in place of Word
documents, because firstly they are usually smaller and quicker to
download and secondly they're ASCII based, so do not require the overhead
of anything of the scale of the Word Object Library to manipulate them. In
fact, all the RTF template editing was undertaken by VB's
file-handling. Consider the RTF table below containing 2 columns,
each with its own justified text.

The rtf file that forms this simple document contains lines & lines
of formatting as ASCII characters, but searching for the text in the cells
returns the following line associated specifically with this grid and text:
{\f28 Data Title:\par }\pard\plain \ql \li0\ri0\widctlpar\intbl\
faauto\adjustright\rin0\lin0 \fs20\lang2057\langfe1033\cgrid\
langnp2057\langfenp1033 {\b\caps\f28 \cell } {#Data1#}
{\b\caps\f28 \cell }
The line above is actually one continuous line in the rtf file, and is
typical of the length of most of the lines. Then I used the function Line Input #1, strRTFLineData
to retrieve each line from the RTF template. Next the search command
Instr(strRTFLineData, "#Data1")
was employed to determined if the line contained the identifier text to
be replaced. Once located, the identifier text was replaced with the
appropriate data (in this case a string containing data from a table)
using
Replace(strRTFLineData, "#Data1", strDataItem)
Whether a substitution was carried out or not, each input line was
written to a flat file line by line to create an updated RTF file. The
only additional code was to return the output RTF file's path for the ASP
code to locate the newly created report. In reality, as many cells existed
in the several tables in the template RTF, I used a series of if...elseif...else
conditions as follows.
If Instr(strRTFLineData, "#Data1") > 0 Then
'replace & write line to output RTF
ElseIf Instr(strRTFLineData, "#Data2") > 0 Then
'replace & write line to output RTF
ElseIf Instr(strRTFLineData, "#Data3") > 0 Then
'replace & write line to output RTF
Else
'just write line to output RTF
End If
The code was then compiled as an ActiveX DLL and registered on the web
server.
|