1. iText# (iTextSharp) is a port of the iText open source java library for PDF generation written entirely in C# for the .NET platform.
You can download from http://sourceforge.net/projects/itextsharp/
2.Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.IO;
using iTextSharp.text;
using iTextSharp.text.html;
using iTextSharp.text.pdf;
using System.Collections;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string path = Server.MapPath("PDF");
/*Logo Path*/
string strLogoPath = Server.MapPath("Image") + "\\jayendra.jpg";
Document doc = new Document(PageSize.LETTER, 25F, 25F, 50F, 25F);
PdfWriter.GetInstance(doc, new FileStream(path + "/Font.pdf", FileMode.Create));
doc.Open();
Rectangle page = doc.PageSize;
Font Verdana = FontFactory.GetFont("Verdana", 10F, Font.NORMAL, BaseColor.BLACK);
PdfPTable table = new PdfPTable(2);
table.TotalWidth = page.Width;
PdfPCell cell = new PdfPCell();
cell.Colspan = 3;
cell.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(strLogoPath);
AddImageInCell(cell, image, 200f, 200f, 1);
cell.Border = 0;
AddtextCell(table, cell, 0, 0, 0);
PdfPCell cell2 = new PdfPCell();
PdfPTable table2 = new PdfPTable(1);
PdfPCell line_2 = new PdfPCell(new Phrase("Name: Gohil Jayendrasinh F", Verdana));
AddtextCell(table2, line_2);
PdfPCell line_3 = new PdfPCell(new Phrase("Email: [email protected]", Verdana));
AddtextCell(table2, line_3);
PdfPCell line_4 = new PdfPCell(new Phrase("Compny Name: SIGMASOLVE LLC", Verdana));
AddtextCell(table2, line_4);
cell2.AddElement(table2);
cell2.Border = 0;
AddtextCell(table, cell2, 0, 0, 0);
doc.Add(table);
doc.Close();
}
private static void AddImageInCell(PdfPCell cell, iTextSharp.text.Image image, float fitWidth, float fitHight, int Alignment)
{
image.ScaleToFit(fitWidth, fitHight);
image.Alignment = Alignment;
cell.AddElement(image);
}
private void AddtextCell(PdfPTable table, PdfPCell cell)
{
cell.Colspan = 3;
cell.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
cell.Border = 0;
table.AddCell(cell);
}
private void AddtextCell(PdfPTable table, PdfPCell cell, float paddingLeft, float paddingRight)
{
cell.Colspan = 3;
cell.HorizontalAlignment = 0; //0=Left, 1=Centre, 2=Right
cell.PaddingLeft = paddingLeft;
cell.PaddingRight = paddingRight;
cell.Border = 0;
table.AddCell(cell);
}
private void AddtextCell(PdfPTable table, PdfPCell cell, float paddingLeft, float paddingRight, int hAlign)
{
cell.Colspan = 3;
cell.HorizontalAlignment = hAlign; //0=Left, 1=Centre, 2=Right
cell.PaddingLeft = paddingLeft;
cell.PaddingRight = paddingRight;
cell.Border = 0;
table.AddCell(cell);
}
private static void AddtextCell(PdfPTable table, PdfPCell cell, int Colspan, int HorizontalAlignment, int Border)
{
cell.Colspan = Colspan;
cell.HorizontalAlignment = HorizontalAlignment; //0=Left, 1=Centre, 2=Right
cell.Border = Border;
table.AddCell(cell);
}
}
That's it.

RakeshReddy sPosted Feb 25, 2016, 4:32 AM
i am not getting the border of pdf when it is converted, please any on help me
Bhanu Pratap SinghPosted Jun 12, 2013, 2:11 AM
I am unable to Create pdf of a page which contains Chart control and i am unable to generate design so i need quick assistance ,
hari haranPosted Mar 18, 2013, 2:15 AM
thank you ..this code help full for me
Skip FloydPosted Mar 12, 2013, 10:30 AM
Can you add a checkbox to a CELL?
Gohil JayendrasinhPosted Sep 25, 2012, 7:22 AM
no. you can add color class and call it.
Gohil JayendrasinhPosted Sep 25, 2012, 7:22 AM
no. you can add color class and call it.
hemant SaliyaPosted Sep 14, 2012, 6:17 AM
Can I insert an External CSS File into a PDF generated by ITextSharp
Sunil GuptaPosted Feb 21, 2011, 11:43 PM
Hi Jayendrasinh Gohil this is very nice post. i need a help. i have an image of coupon. and i have to add coupon number on image and convert it to pdf. i tried to convert image into html overlay a div to image to add coupon no. but it not converting in pdf please help. it is very urgent
ali ahsanPosted Feb 11, 2011, 6:20 AM
Good Post. I want to add image in the pdf file using itext sharp.The image is so large that it not entirely display on the pdf file and is cutting from the bottom. if u have any sol of the above prob,this could be very helpful for me.