TX Text Control系列教程— ASP.NET : 告教程

本教程将会介绍如何使用ASP.NET Web应用程序中的MailMerge组件将模板与数据合并以创建Adobe PDF文档。

    TX Text Control Server for ASP.NET (incl. WPF)是一个企业级的服务器端文字处理控件。它为用于ASP.NET服务器环境提供一个完全可编程的文字处理引擎,并且包含一个WPF客户端版本。

TX Text Control Server for ASP.NET (incl. WPF)最新试用版


创建第一个 表应用程序

  1. 打开Visual Studio并创建一个新的ASP.NET空Web应用程序。

    tutorial_aspnet_reporting_1.png
  2. 在Solution Explorer中,选择项目,然后从项目主菜单中选择Add New Item …. ,在打开的对话框的添加新项目中,选择Web窗体并使用添加确认。 

    tutorial_aspnet_reporting_2.png
  3. 在Solution Explorer中,选择新创建的Web窗体,然后从View主菜单中选择Component Designer。在工具箱中找到MailMerge组件,然后将实例拖放到组件设计器表单上。然后使用ServerTextControl组件重复此步骤。

    tutorial_aspnet_reporting_3.png
  4. 选择MailMerge组件并将TextComponent属性设置为serverTextControl1 – 插入的ServerTextControl实例的名称。

    tutorial_aspnet_reporting_4.png
  5. 在解决方案资源管理器中选择项目时,从项目主菜单中选择Add New Item ….,在打开的对话框的添加现有项中,浏览到以下示例文件夹:

     %USERPROFILE%DocumentsTX Text Control 27.0.NET Server for ASP.NETSamplesASP.NETCSharp(或者VB.NET)Documentation TutorialsMailMergeTutorial

  6. 选择以下2个文件:template.docx和sample_db.xml,然后单击添加按钮。

    tutorial_aspnet_reporting_5.png
  7. 在Solution Explorer中选择Web Form,然后从View主菜单中选择Designer,在工具箱中找到Button控件,然后将实例拖放到Web窗体上。

    tutorial_aspnet_reporting_6.png
  8. 双击该按钮并将以下代码插入事件处理程序:

    CS:

    protected void Button1_Click(object sender, EventArgs e)    {    // create a DataSet from the sample XML data source    System.Data.DataSet ds = new System.Data.DataSet();    ds.ReadXml(Server.MapPath("sample_db.xml"), System.Data.XmlReadMode.Auto);    // load the template    mailMerge1.LoadTemplate(Server.MapPath("template.docx"),    TXTextControl.DocumentServer.FileFormat.WordprocessingML);    // merge the template with data    mailMerge1.Merge(ds.Tables[0]);    // save the document as PDF into a byte array    byte[] data;    mailMerge1.SaveDocumentToMemory(out data,    TXTextControl.BinaryStreamType.AdobePDF, null);    // return the document to the browser for download    Response.Clear();    Response.AddHeader("content-disposition",    String.Format("attachment;filename={0}", "created_by_txtextcontrol.pdf"));    Response.ContentType = "application/pdf";    Response.BinaryWrite(data);    Response.End();    }    Sign up for free

    VB:

    Protected Sub Button1_Click(sender As Object, e As EventArgs)    ' create a DataSet from the sample XML data source    Dim ds As New System.Data.DataSet()    ds.ReadXml(Server.MapPath("sample_db.xml"), System.Data.XmlReadMode.Auto)    ' load the template    mailMerge1.LoadTemplate(Server.MapPath("template.docx"),    TXTextControl.DocumentServer.FileFormat.WordprocessingML)    ' merge the template with data    mailMerge1.Merge(ds.Tables(0))    ' save the document as PDF into a byte array    Dim data As Byte()    mailMerge1.SaveDocumentToMemory(data,    TXTextControl.BinaryStreamType.AdobePDF, Nothing)    ' return the document to the browser for download    Response.Clear()    Response.AddHeader("content-disposition",    [String].Format("attachment;filename={0}", "created_by_txtextcontrol.pdf"))    Response.ContentType = "application/pdf"    Response.BinaryWrite(data)    Response.[End]()    End Sub
  9. 在同一代码视图中,将以下代码添加到Page_Load事件:

    CS:

    protected void Page_Load(object sender, EventArgs e)    {    InitializeComponent();    }

    VB:

    Protected Sub Page_Load(sender As Object, e As EventArgs)    InitializeComponent()    End Sub
  10. 编译并启动应用程序。按按钮创建以PDF文件形式返回的 告。

 ASP.NET部分使用教程的第一步就完成了,接下来将会介绍AJAX应用程序的创建。


.jpg   

标签:

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2019年7月3日
下一篇 2019年7月3日

相关推荐

发表回复

登录后才能评论