This message contains graphics. If you do not see the graphics: Graphic Version.
How to use TX Text Control ActiveX Server in ASP.NET

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:

<%@ 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:

tx.Load(Server.MapPath("template.rtf"), 0, 5, 0) tx.Find("Title:") TableId = tx.TableAtInputPos ' loop through the DropDownLists ' to get the selected values For i = 0 To (DropDownList2.Items.Count - 1) If DropDownList2.Items(i).Selected Then text_noteMaker = DropDownList2.Items(i).Text End If Next For i = 0 To (DropDownList1.Items.Count - 1) If DropDownList1.Items(i).Selected Then text_typeOfMeeting = DropDownList1.Items(i).Text End If Next ' fill the table with the content tx.TableCellText(TableId,1,2) = TextBox1.Text tx.TableCellText(TableId,2,2) = text_noteMaker tx.TableCellText(TableId,1,4) = text_typeOfMeeting 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.

data = tx.SaveToMemoryBuffer(data, exportFormat, 0) Response.Clear if exportFormat = 12 then Response.ContentType = "application/pdf" Response.AddHeader("Content-Disposition", "attachment;_ filename=meeting_minutes.pdf") Response.BinaryWrite(data) else if exportFormat = 9 then Response.ContentType = "application/doc" Response.AddHeader("Content-Disposition", "attachment;_ filename=meeting_minutes.doc") Response.BinaryWrite(data) else if exportFormat = 5 Response.ContentType = "application/rtf" Response.AddHeader("Content-Disposition", "attachment;_ filename=meeting_minutes.rtf") Response.Write(data) end if Response.End

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

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.

Best regards

The Newsletter Team

Text Control GmbH respects your online time and privacy. We only send this newsletter to TX Text Control customers and people who have signed up to receive it. However, if you would prefer not to receive future issues of the newsletter, you may unsubscribe at any time. If you received this newsletter forwarded from a colleague or friend, you may wish to subscribe directly.

Sent to: N/A.

Imprint | Unsubscribe | Subscribe

© 2020 Text Control GmbH. All Rights Reserved.