Set font for all text from Pdfptable with Itextsharp

后端 未结 2 938
清歌不尽
清歌不尽 2021-01-26 16:17
var htmlarraylist = HTMLWorker.ParseToList(new StringReader(htmlText), styles);
document.Open();

BaseFont Vn_Helvetica = BaseFont.CreateFont(@\"C:\\Windows\\Fonts\\aria         


        
相关标签:
2条回答
  • 2021-01-26 16:17

    i have try set font family in pdf template. and show the following error also

    'BaseFont' does not contain a definition for 'Cambria'

    please suggest me...thanks

    public void abcd()
            {
                try
                {
                    string UniqueNumber = Request.QueryString["UniqueNumber"];
                    string strFileName = UniqueNumber;
                    string strFileExtension = ".pdf";
                    string strContentType = FileManager.FileContentType_application_pdf;
                    string strExportData = string.Empty;
                    Document pdfDoc = new Document();
                    HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
                    var output = new MemoryStream();
                    BaseFont bfTimes = BaseFont.CreateFont(BaseFont.Cambria, BaseFont.CP1252, false);
                    //Font ChronicleFont = new Font(bfTimes, 26f);
                    StringWriter sw = new StringWriter();
                    HtmlTextWriter htw = new HtmlTextWriter(sw);
                    StringReader sr;
                    sr = new StringReader(Convert.ToString(ExportData.UserDetails(UniqueNumber)));
                    PdfWriter.GetInstance(pdfDoc, output);
                    pdfDoc.Open();
                    htmlparser.Parse(sr);
                    pdfDoc.Close();
                    strFileName = strFileName.Replace(" - ", "-").Replace(" ", "-").Replace("--", "-");
                    Response.ClearContent();
                    Response.Buffer = true;
                    Response.AddHeader("content-disposition", string.Format("attachment; filename={0}{1}", strFileName, strFileExtension));
                    Response.ContentType = strContentType;
                    Response.Charset = "";
                    Response.BinaryWrite(output.ToArray());
                    Response.Flush();
                    Response.End();
    
                }
                catch (Exception ex)
                {
                    //
    
                }
            }
    
    0 讨论(0)
  • 2021-01-26 16:31

    Please try by setting font to the PdfPTable.DefaultCell property in you foreach loop

    Example:
    t.DefaultCell.Phrase = new Phrase() { Font = fontNormal };
    
    0 讨论(0)
提交回复
热议问题