#region
private void M_createPDF()
{
string path = Server.MapPath("PDF");
/*Logo Path*/
string strLogoPath = Server.MapPath("images") + "\\clock.png";
Document doc = new Document(PageSize.LETTER, 25F, 25F, 50F, 25F);
PdfWriter.GetInstance(doc, new FileStream(path + "/Font.pdf", FileMode.Create));
string imageFilePath = Server.MapPath(".") + "/images/pageheader_bckgr.gif";
iTextSharp.text.Image jpg = iTextSharp.text.Image.GetInstance(imageFilePath);
jpg.ScaleToFit(3000, 770);
//If you want to choose image as background then,
jpg.Alignment = iTextSharp.text.Image.UNDERLYING;
//If you want to give absolute/specified fix position to image.
jpg.SetAbsolutePosition(7, 69);
doc.Open();
Rectangle page = doc.PageSize;
Font Verdana = FontFactory.GetFont("Verdana", 10F, Font.NORMAL, BaseColor.BLACK);
PdfPTable table = new PdfPTable(5);
PdfPCell cell = new PdfPCell(new Phrase("Header spanning 3 columns"));
//float[] widths = new float[] { 1f, 1f };
//table.SetWidths(widths);
cell.Colspan = 5;
cell.BackgroundColor = BaseColor.GRAY;
cell.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
table.AddCell(cell);
table.AddCell("Sr.No");
table.AddCell("Name");
table.AddCell("J1");
table.AddCell("J2");
table.AddCell("J3");
for (int i = 0; i < 10; i++)
{
if (i == 5)
{
cell = new PdfPCell(new Phrase("Header spanning 3 columns"));
cell.BackgroundColor = BaseColor.GRAY;
cell.Colspan = 5;
cell.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
table.AddCell(cell);
}
cell = new PdfPCell(new Phrase(i.ToString()));
Rectangle _r = new Rectangle(2, 2, 2, 2, 180);
cell.FixedHeight = 20.0f;
//cell.Width = _r.Width;
table.AddCell(cell);
table.AddCell("Name" + i.ToString());
table.AddCell(i.ToString());
table.AddCell((i + 1).ToString());
table.AddCell((i + 2).ToString());
}
doc.Add(jpg);
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);
}
#endregion