如何在PdfWriter中应用自定义字体系列iTextSharp(HTML到PDF)?

时间:2018-11-10 12:52:31

标签: c#

我想使用字符串生成器从HTML生成PDF。在该PDF报告中,我必须应用自定义字体。以下是我尝试的示例源代码。任何人都可以找到解决方案?。谢谢

StringBuilder sb = new StringBuilder();
sb.Append("<p>New Font Family</p>");
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();

0 个答案:

没有答案