ASP User's Guide
This example shows how to use TX Text Control to create documents on-the-fly without any server-side user interaction. It uses input information from a web site, creates a document and returns a print-ready PDF document. You will find this sample in the Samples\Asp\OnlineStore directory.
The example environment is an online store shopping cart where the user can specify the quantity of articles in the cart. After specifying the postal address and pressing the Order button, the data is used to create an order confref_descirmation on the server. The data is sent to the server using the HTTP POST variables where the ASP script creates a Text Control object.
<form action="create_confirmation.asp" method="post" ID="Form1">
First of all, a template document is loaded that already contains the design of the invoice. The template generation is omitted for clarity in this sample. If you want to know more about template generation, please have a look at the Mail Merge sample in the Visual Basic User's Guide.
' Load a template file tx.Load Server.MapPath("template.tx") ' Merge the marked text fields with the posted data tx.FieldCurrent = 1 tx.FieldText = request.form("company") tx.FieldCurrent = 2 tx.FieldText = request.form("street")
Mail merge is then performed on the fields already present in the template, filling them with values like name or address. The fields were inserted with the template generator and they are used as placeholders for the form's data. For a detailed ref_descoverview of all text field capabilities see Technical Articles - Marked Text Fields.
Now it is time to put the ordered items into a table. The table is also an element of the template document. For each item whose quantity is greater than zero, a new line is inserted into the table and the item's product description is copied to ref_descthe new row.
For i = 1 To request.form("article_amount") If(request.form("article" + CStr(i) + "_qty") <> 0) Then tx.SelStart = tx.TableCellStart(TableID, _ tx.TableRows(TableID), 1) tx.TableInsertLines 2, 1 tx.TableCellText(TableID, CurrentRow, 1) = _ request.form("article" + CStr(i) + "_qty") tx.TableCellText(TableID, CurrentRow, 2) = _ request.form("article" + CStr(i) + "_ordernumber") tx.TableCellText(TableID, CurrentRow, 3) = _ request.form("article" + CStr(i) + "_description") article_sum = request.form("article" _ + CStr(i)+"_qty") _ * request.form("article" + CStr(i) + "_price") TotalSum = TotalSum + article_sum tx.TableCellText(TableID, CurrentRow, 4) = _ FormatNumber (article_sum, 2) & " US $" CurrentRow = CurrentRow + 1 End If Next
Finally, the grand total is calculated and copied to the last row in the table. The final step is to use the SaveToMemoryBuffer method to save the document in the desired format to a local buffer which isref_desc sent to the user via Response.BinaryWrite. In this case we are going to save in PDF.
' Write the contents as a PDF document to a variable and ' return it to the client OutputBuffer = tx.SaveToMemoryBuffer(OutputBuffer, 12, 0) Response.Clear Response.ContentType = "application/pdf" Response.AddHeader "Content-Disposition", "attachment; filename=order.pdf" Response.BinaryWrite(OutputBuffer)