Apply custom font family iTextSharp(HTML to PDF)

Nov 10 2018 6:41 AM
I want to generate PDF from HTML using string builder.In that PDF report I have to apply custom fonts.Here is the sample source code which i tried.Can anyone have solutions?.Thanks
 
StringBuilder sb = new StringBuilder();
sb.Append("New Font Family");
MemoryStream HTMLstream = new MemoryStream(Encoding.UTF8.GetBytes(sb.ToString()));
MemoryStream cssstream = new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(System.IO.File.ReadAllText(HttpContext.Current.Server.MapPath("../Assets/css/pregamereport.css"))));
iTextSharp.text.Rectangle pageSize = new iTextSharp.text.Rectangle(613, 800);
Document pdfDoc = new Document(PageSize.A4, 10f, 20f, 20f, 1f);
fileName = "test";
string ReportLoaction = ConfigurationManager.AppSettings["BoxScoreReport"];
string newStatslocationsite = System.Web.HttpContext.Current.Server.MapPath(ReportLoaction);
if (!Directory.Exists(newStatslocationsite))
{
Directory.CreateDirectory(newStatslocationsite);
}
string finalpath = Path.Combine(newStatslocationsite, fileName);
FileStream createReport = new FileStream(finalpath, FileMode.Create);
PdfWriter writer = PdfWriter.GetInstance(pdfDoc, createReport);
pdfDoc.Open();
XMLWorkerHelper.GetInstance().ParseXHtml(writer, pdfDoc, HTMLstream, cssstream);
pdfDoc.Close();

Answers (4)