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.Draw Line separator in PDF using iTextSharp in ASP.Net<p>Hi <a class="username" rel="smile">smile</a>,</p> <p>Please refer below sample and adjust the line gap as per your requirement.</p> <p><span style="text-decoration: underline;"><strong>Namespaces</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">using System.IO; using iTextSharp.text; using iTextSharp.text.pdf;</pre> <p><strong>VB.Net</strong></p> <pre class="brush: csharp">Imports System.IO Imports iTextSharp.text Imports iTextSharp.text.pdf</pre> <p><span style="text-decoration: underline;"><strong>Code</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">protected void Page_Load(object sender, EventArgs e) { &nbsp;&nbsp;&nbsp; Document document = new Document(PageSize.A4, 88f, 88f, 10f, 10f); &nbsp;&nbsp;&nbsp; using (MemoryStream memoryStream = new MemoryStream()) &nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PdfWriter writer = PdfWriter.GetInstance(document, memoryStream); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.Open(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Paragraph lineSeparator = new Paragraph(new Chunk(new iTextSharp.text.pdf.draw.LineSeparator(0.0F, 100.0F, Color.BLACK, Element.ALIGN_LEFT, 1))); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Set gap between line paragraphs. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lineSeparator.SetLeading(0.5F, 0.5F); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Paragraph par = new Paragraph(&#34; &#34;); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Set gap between text paragraphs. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; par.SetLeading(0.7F, 0.7F); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.Add(new Paragraph(&#34;&nbsp;&nbsp;&nbsp; i.&nbsp;&nbsp;&nbsp;&nbsp; How Many words for colours are there in the poem?&#34;)); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.Add(par); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.Add(lineSeparator); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.Add(lineSeparator); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.Add(lineSeparator); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.Add(lineSeparator); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.Add(lineSeparator); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.Add(new Paragraph(&#34;&nbsp;&nbsp;&nbsp; ii.&nbsp;&nbsp;&nbsp;&nbsp; Where will the boatgo?&#34;)); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.Add(par); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.Add(lineSeparator); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.Add(lineSeparator); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.Add(lineSeparator); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.Add(lineSeparator); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.Add(lineSeparator); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.Add(new Paragraph(&#34;&nbsp;&nbsp;&nbsp; iii.&nbsp;&nbsp;&nbsp;&nbsp; Which son could see everythings?&#34;)); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.Add(par); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.Add(lineSeparator); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.Add(lineSeparator); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.Add(lineSeparator); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.Add(lineSeparator); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.Add(lineSeparator); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.Close(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; byte[] bytes = memoryStream.ToArray(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; memoryStream.Close(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Response.Clear(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Response.ContentType = &#34;application/pdf&#34;; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Response.AddHeader(&#34;Content-Disposition&#34;, &#34;attachment; filename=Employee.pdf&#34;); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Response.ContentType = &#34;application/pdf&#34;; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Response.Buffer = true; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Response.Cache.SetCacheability(HttpCacheability.NoCache); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Response.BinaryWrite(bytes); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Response.End(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Response.Close(); &nbsp;&nbsp;&nbsp; } }</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load &nbsp;&nbsp;&nbsp; Dim document As Document = New Document(PageSize.A4, 88.0F, 88.0F, 10.0F, 10.0F) &nbsp;&nbsp;&nbsp; Using memoryStream As MemoryStream = New MemoryStream() &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim writer As PdfWriter = PdfWriter.GetInstance(document, memoryStream) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.Open() &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim lineSeparator As Paragraph = New Paragraph(New Chunk(New iTextSharp.text.pdf.draw.LineSeparator(0.0F, 100.0F, Color.BLACK, Element.ALIGN_LEFT, 1))) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lineSeparator.SetLeading(0.5F, 0.5F) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim par As Paragraph = New Paragraph(&#34; &#34;) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; par.SetLeading(0.7F, 0.7F) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.Add(New Paragraph(&#34;&nbsp;&nbsp;&nbsp; i.&nbsp;&nbsp;&nbsp;&nbsp; How Many words for colours are there in the poem?&#34;)) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.Add(par) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.Add(lineSeparator) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.Add(lineSeparator) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.Add(lineSeparator) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.Add(lineSeparator) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.Add(lineSeparator) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.Add(New Paragraph(&#34;&nbsp;&nbsp;&nbsp; ii.&nbsp;&nbsp;&nbsp;&nbsp; Where will the boatgo?&#34;)) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.Add(par) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.Add(lineSeparator) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.Add(lineSeparator) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.Add(lineSeparator) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.Add(lineSeparator) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.Add(lineSeparator) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.Add(New Paragraph(&#34;&nbsp;&nbsp;&nbsp; iii.&nbsp;&nbsp;&nbsp;&nbsp; Which son could see everythings?&#34;)) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.Add(par) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.Add(lineSeparator) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.Add(lineSeparator) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.Add(lineSeparator) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.Add(lineSeparator) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.Add(lineSeparator) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.Close() &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim bytes As Byte() = memoryStream.ToArray() &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; memoryStream.Close() &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Response.Clear() &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Response.ContentType = &#34;application/pdf&#34; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Response.AddHeader(&#34;Content-Disposition&#34;, &#34;attachment; filename=Employee.pdf&#34;) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Response.ContentType = &#34;application/pdf&#34; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Response.Buffer = True &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Response.Cache.SetCacheability(HttpCacheability.NoCache) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Response.BinaryWrite(bytes) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Response.End() &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Response.Close() &nbsp;&nbsp;&nbsp; End Using End Sub</pre> <p><span style="text-decoration: underline;"><strong>Screenshot</strong></span></p> <p><img src="https://i.imgur.com/TPsa0Pf.jpg" alt="" width="472" height="199" /></p>https://www.aspforums.net:443/Threads/103476/Draw-Line-separator-in-PDF-using-iTextSharp-in-ASPNet/https://www.aspforums.net:443/Threads/103476/Draw-Line-separator-in-PDF-using-iTextSharp-in-ASPNet/Fri, 05 Oct 2018 00:59:37 GMT