Skype:TextControlSupport
Orders:877-462-4772
TX Text Control - word processing components.

How to use TX Text Control ActiveX Server in ASP.NET

Topics for Thursday, August 14 2003

How to use TX Text Control ActiveX Server in ASP.NET

Click to enlarge

As you can guess from its name, TX Text Control ActiveX Server is an ActiveX that is usually deployed in ASP, however, it is equally possible to use it with ASP.NET.

In this newsletter, we are going to show you how to create a WinForms application in Visual Studio .NET that creates PDF, DOC and RTF files from data entered on a web page.

Note that TX Text Control is running server-side and not on the client. Data is entered in simple HTML text boxes, sent to TX Text Control ActiveX Server and then posted back in the required format.

How it works

TX Text Control ActiveX Server can be used in ASP.NET projects as long as ASP compatibility has been enabled. The property aspCompat of the ASP.NET file must be set to true, thus the first ASP tag must look like this:

  1. <%@ Page aspCompat="True" Language="vb" ... %>

The sample application will create meeting minutes with data from a web page and convert it to a PDF, DOC or RTF file. The finished application will have text input areas for:

  • Meeting name
  • Date of the meeting
  • Attendees
  • Meeting minutes

The document will be dynamically created using the data from the WebForm. After the end-user has filled in the form, s/he will be able to choose between three document formats (PDF, MS Word or RTF), click 'Submit' and the content will be posted to the server in the specified format.

Code overview

First of all, we load a template into TX Text Control. This will be filled with form data later on:

  1. tx.Load(Server.MapPath("template.rtf"), 0, 5, 0)
  2.  
  3. tx.Find("Title:")
  4. TableId = tx.TableAtInputPos
  5.  
  6. ' loop through the DropDownLists
  7. ' to get the selected values
  8. For i = 0 To (DropDownList2.Items.Count - 1)
  9. If DropDownList2.Items(i).Selected Then
  10. text_noteMaker = DropDownList2.Items(i).Text
  11. End If
  12. Next
  13.  
  14. For i = 0 To (DropDownList1.Items.Count - 1)
  15. If DropDownList1.Items(i).Selected Then
  16. text_typeOfMeeting = DropDownList1.Items(i).Text
  17. End If
  18. Next
  19.  
  20. ' fill the table with the content
  21. tx.TableCellText(TableId,1,2) = TextBox1.Text
  22. tx.TableCellText(TableId,2,2) = text_noteMaker
  23. tx.TableCellText(TableId,1,4) = text_typeOfMeeting
  24. tx.TableCellText(TableId,2,4) = Calendar1.SelectedDate.Date

After the document has been merged with the data, it is sent back to the browser. The document will be exported depending on the specified format.

  1. data = tx.SaveToMemoryBuffer(data, exportFormat, 0)
  2.  
  3. Response.Clear
  4.  
  5. if exportFormat = 12 then
  6. Response.ContentType = "application/pdf"
  7. Response.AddHeader("Content-Disposition", "attachment;_
  8. filename=meeting_minutes.pdf")
  9. Response.BinaryWrite(data)
  10. else if exportFormat = 9 then
  11. Response.ContentType = "application/doc"
  12. Response.AddHeader("Content-Disposition", "attachment;_
  13. filename=meeting_minutes.doc")
  14. Response.BinaryWrite(data)
  15. else if exportFormat = 5
  16. Response.ContentType = "application/rtf"
  17. Response.AddHeader("Content-Disposition", "attachment;_
  18. filename=meeting_minutes.rtf")
  19. Response.Write(data)
  20. end if
  21.  
  22. Response.End

To see the application in action, please take a look at the following live demonstration:

You can download the ASP.NET source code to this sample application at:

Download Download [35.68 KB, ZIP] the sample application ZIP file to try out this application yourself.

System requirements

TX Text Control ActiveX Server, Visual Studio .NET 2002 and an ASP.NET enabled Microsoft Internet Information Server (IIS) are required to test this project on your computer. Copy the project files into a folder on your machine and create a 'Virtual Directory' in IIS which points to that folder.

External verification page for ISO 9000:2000 certificate
ISO 9001:2000
certified