Hi mahesh213,
Check the below example and implement in your code.
To draw Line with color use LineSeparator and set the Color as per your need.
Namespaces
C#
using System.IO;
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.pdf.draw;
VB.Net
Imports System.IO
Imports iTextSharp.text
Imports iTextSharp.text.pdf
Imports iTextSharp.text.pdf.draw
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
Document document = new Document(PageSize.A4, 88f, 88f, 10f, 10f);
using (MemoryStream memoryStream = new MemoryStream())
{
PdfWriter writer = PdfWriter.GetInstance(document, memoryStream);
document.Open();
document.Add(new Paragraph("Line 1"));
Paragraph paragraph = new Paragraph(new Chunk(new LineSeparator(1F, 10.0F, Color.BLUE, Element.ALIGN_LEFT, 1)));
paragraph.SetLeading(0.5F, 0.5F);
document.Add(paragraph);
document.Add(new Paragraph("Line 2"));
document.Add(new Paragraph(" "));
LineSeparator line = new LineSeparator(1f, 10f, Color.RED, Element.ALIGN_LEFT, 1);
document.Add(line);
document.Close();
byte[] bytes = memoryStream.ToArray();
memoryStream.Close();
Response.Clear();
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Disposition", "attachment; filename=Sample.pdf");
Response.ContentType = "application/pdf";
Response.Buffer = true;
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.BinaryWrite(bytes);
Response.End();
Response.Close();
}
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
Dim document As Document = New Document(PageSize.A4, 88.0F, 88.0F, 10.0F, 10.0F)
Using memoryStream As MemoryStream = New MemoryStream()
Dim writer As PdfWriter = PdfWriter.GetInstance(document, memoryStream)
document.Open()
document.Add(New Paragraph("Line 1"))
Dim paragraph As Paragraph = New Paragraph(New Chunk(New LineSeparator(1.0F, 10.0F, Color.BLUE, Element.ALIGN_LEFT, 1)))
paragraph.SetLeading(0.5F, 0.5F)
document.Add(paragraph)
document.Add(New Paragraph("Line 2"))
document.Add(New Paragraph(" "))
Dim line As LineSeparator = New LineSeparator(1.0F, 10.0F, Color.RED, Element.ALIGN_LEFT, 1)
document.Add(line)
document.Close()
Dim bytes As Byte() = memoryStream.ToArray()
memoryStream.Close()
Response.Clear()
Response.ContentType = "application/pdf"
Response.AddHeader("Content-Disposition", "attachment; filename=Sample.pdf")
Response.ContentType = "application/pdf"
Response.Buffer = True
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.BinaryWrite(bytes)
Response.End()
Response.Close()
End Using
End Sub
Screenshot
![](https://i.imgur.com/Mspy3Wm.jpg)