ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Export multiline TextBox content with formatting to PDF in ASP.Net<p>Hi <a class="username" rel="charles"> charles</a>,</p> <p>Please refer below sample.</p> <p>If you want to more alignment and design so for that refer below article -</p> <h1 class="header"><a title="How to generate and download PDF Report from database in ASP.Net using iTextSharp C# and VB.Net'a" href="https://www.aspsnippets.com/Articles/How-to-generate-and-download-PDF-Report-from-database-in-ASPNet-using-iTextSharp-C-and-VBNet.aspx">How to generate and download PDF Report from database in ASP.Net using iTextSharp C# and VB.Net</a></h1> <p><span style="text-decoration: underline;"><strong>HTML</strong></span></p> <pre class="brush: html">&lt;div&gt; &lt;asp:TextBox ID=&#34;txtTextBox1&#34; runat=&#34;server&#34; TextMode=&#34;MultiLine&#34; Height=&#34;100px&#34; Width=&#34;250px&#34;&gt;&lt;/asp:TextBox&gt; &lt;asp:Button ID=&#34;btnMakePDF&#34; runat=&#34;server&#34; OnClick=&#34;MakePDF&#34; Text=&#34;Submit&#34; /&gt; &lt;/div&gt;</pre> <p><span style="text-decoration: underline;"><strong>Namespaces</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">using iTextSharp.text; using iTextSharp.text.pdf; using System.Text.RegularExpressions;</pre> <p><strong>Vb.Net</strong></p> <pre class="brush: vb">Imports iTextSharp.text.pdf Imports iTextSharp.text</pre> <p><span style="text-decoration: underline;"><strong>Code</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">protected void MakePDF(object sender, EventArgs e) { Phrase phrase = new Phrase(); string[] lines = Regex.Split(txtTextBox1.Text, &#34;\r\n&#34;); foreach (string item in lines) { phrase.Add(new Chunk(&#34;&#34; + item.ToString() + &#34;\n&#34;)); } Document document = new Document(PageSize.A4, 10f, 10f, 10f, 10f); using (System.IO.MemoryStream memoryStream = new System.IO.MemoryStream()) { PdfWriter writer = PdfWriter.GetInstance(document, memoryStream); document.Open(); document.Add(phrase); document.Close(); byte[] bytes = memoryStream.ToArray(); memoryStream.Close(); Response.Clear(); Response.ContentType = &#34;application/pdf&#34;; Response.AddHeader(&#34;Content-Disposition&#34;, &#34;attachment; filename=Test.pdf&#34;); Response.ContentType = &#34;application/pdf&#34;; Response.Buffer = true; Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.BinaryWrite(bytes); Response.End(); Response.Close(); } } public override void VerifyRenderingInServerForm(Control control) { /* Verifies that the control is rendered */ }</pre> <p><strong>Vb.Net</strong></p> <pre class="brush: vb">Protected Sub MakePDF(ByVal sender As Object, ByVal e As EventArgs) Dim phrase As Phrase = New Phrase() Dim lines As String() = Regex.Split(txtTextBox1.Text, vbCrLf) For Each item As String In lines phrase.Add(New Chunk(&#34;&#34; &amp; item.ToString() &amp; vbLf)) Next Dim document As iTextSharp.text.Document = New iTextSharp.text.Document(PageSize.A4, 10.0F, 10.0F, 10.0F, 10.0F) Using memoryStream As System.IO.MemoryStream = New System.IO.MemoryStream() Dim writer As PdfWriter = PdfWriter.GetInstance(document, memoryStream) document.Open() document.Add(phrase) document.Close() Dim bytes As Byte() = memoryStream.ToArray() memoryStream.Close() Response.Clear() Response.ContentType = &#34;application/pdf&#34; Response.AddHeader(&#34;Content-Disposition&#34;, &#34;attachment; filename=Test.pdf&#34;) Response.ContentType = &#34;application/pdf&#34; Response.Buffer = True Response.Cache.SetCacheability(HttpCacheability.NoCache) Response.BinaryWrite(bytes) Response.[End]() Response.Close() End Using End Sub Public Overrides Sub VerifyRenderingInServerForm(ByVal control As Control) End Sub</pre> <p><span style="text-decoration: underline;"><strong>Screenshot</strong></span></p> <p><img src="https://i.imgur.com/7lIfNoQ.jpg" alt="" width="336" height="387" /></p>https://www.aspforums.net:443/Threads/851748/Export-multiline-TextBox-content-with-formatting-to-PDF-in-ASPNet/https://www.aspforums.net:443/Threads/851748/Export-multiline-TextBox-content-with-formatting-to-PDF-in-ASPNet/Mon, 30 Jul 2018 23:59:30 GMT