private void HTMLtoPDF()
{
try
{
string sFilePath = "C:/Users/NandaKishore.K/Desktop/";
FileStream fs = File.Create(sFilePath + "SamplePDF.pdf");
Document document = new Document();
BaseFont bfR = iTextSharp.text.pdf.BaseFont.CreateFont(BaseFont.TIMES_ROMAN, iTextSharp.text.pdf.BaseFont.CP1257, iTextSharp.text.pdf.BaseFont.EMBEDDED);
PdfWriter writer = PdfWriter.GetInstance(document, fs);
PdfWriter.GetInstance(document, Response.OutputStream);
document.Open();
document.Add(jpg);
BaseFont bfChronicleFont = BaseFont.CreateFont("C:\\inetpub\\wwwroot\\Practice\\Practice\\Fonts\\ChronicleDisp-Black.otf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
Font ChronicleFont = new Font(bfChronicleFont, 16f);
BaseFont bfBrandonFont = BaseFont.CreateFont("C:\\inetpub\\wwwroot\\Practice\\Practice\\Fonts\\Brandon_reg.otf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
Font BrandonFont = new Font(bfBrandonFont, 14f, Font.NORMAL);
PdfPTable table1 = new PdfPTable(1);
PdfPCell pdfCell;
pdfCell = new PdfPCell(new Phrase("BELLEVUE SQUARE", ChronicleFont));
pdfCell.Border = 0;
pdfCell.PaddingTop = 40;
pdfCell.PaddingLeft = 100;
table1.AddCell(pdfCell);
pdfCell = new PdfPCell(new Phrase("Use our west entrance on two.", BrandonFont));
pdfCell.Border = 0;
pdfCell.PaddingTop = 10;
pdfCell.PaddingLeft = 100;
table1.AddCell(pdfCell);
pdfCell = new PdfPCell(new Phrase("Thursday, November 29, 7:30 p.m.", BrandonFont));
pdfCell.Border = 0;
pdfCell.PaddingLeft = 100;
table1.AddCell(pdfCell);
pdfCell = new PdfPCell(new Phrase(string.Empty));
pdfCell.Border = 0;
pdfCell.FixedHeight = 60;
table1.AddCell(pdfCell);
document.Add(table1);
PdfPTable table2 = new PdfPTable(5);
PdfPCell pdfCell2;
pdfCell2 = new PdfPCell(new Phrase("Name:", BrandonFont));
pdfCell2.PaddingLeft = 100;
pdfCell2.Border = 0;
pdfCell2.Colspan = 3;
table2.AddCell(pdfCell2);
pdfCell2 = new PdfPCell(new Phrase("Name", BrandonFont));
pdfCell2.Border = 0;
table2.AddCell(pdfCell2);
pdfCell2 = new PdfPCell(new Phrase(string.Empty));
pdfCell2.Border = 0;
table2.AddCell(pdfCell2);
pdfCell2 = new PdfPCell(new Phrase("Total Number of Guests:", BrandonFont));
pdfCell2.PaddingLeft = 110;
pdfCell2.PaddingTop = 15;
pdfCell2.Colspan = 3;
pdfCell2.Border = 0;
table2.AddCell(pdfCell2);
pdfCell2 = new PdfPCell(new Phrase("Name", BrandonFont));
pdfCell2.PaddingTop = 15;
pdfCell2.Border = 0;
table2.AddCell(pdfCell2);
pdfCell2 = new PdfPCell(new Phrase(string.Empty));
pdfCell2.Border = 0;
table2.AddCell(pdfCell2);
pdfCell2 = new PdfPCell(new Phrase("Confirmation Number:", BrandonFont));
pdfCell2.PaddingTop = 15;
pdfCell2.Colspan = 3;
pdfCell2.PaddingLeft = 100;
pdfCell2.Border = 0;
table2.AddCell(pdfCell2);
pdfCell2 = new PdfPCell(new Phrase("Name", BrandonFont));
pdfCell2.PaddingTop = 15;
pdfCell2.Border = 0;
table2.AddCell(pdfCell2);
pdfCell2 = new PdfPCell(new Phrase(string.Empty));
pdfCell2.Border = 0;
table2.AddCell(pdfCell2);
pdfCell2 = new PdfPCell(new Phrase(string.Empty));
pdfCell2.Colspan = 5;
pdfCell2.Border = 0;
pdfCell2.FixedHeight = 80;
table2.AddCell(pdfCell2);
document.Add(table2);
document.Close();
fs.Close();
Response.AddHeader("Content-Disposition", "attachment;filename=SamplePDF.pdf");
Response.ContentType = "application/pdf";
Response.TransmitFile("C:\\Users\\NandaKishore.K\\Desktop\\SamplePDF.pdf");
Response.End();
}
catch (Exception ex)
{
}
}