Changing font size of pdfptable

心已入冬 提交于 2019-12-23 23:52:46

问题


How do I set the font for a pdfptable?


回答1:


You must set the font in each cell when you're creating a phrase:

Dim yourFont As BaseFont = BaseFont.CreateFont( _
  Current.Server.MapPath("~/fonts/somefont.TTF"), _
  BaseFont.WINANSI, BaseFont.EMBEDDED)
Dim mainFont As New Font(yourFont, SOME_FONT_SIZE, Font.NORMAL)

Dim cell As New PdfPCell(New Phrase("some text", mainFont))
yourTable.Add(cell)



回答2:


You need to create a 'Base Font' object which is a little different than a regular font object in iTextSharp. You assign the font to each element (phrase, paragraph, etc.) that you create for the PdfPTable.

Dim bfR As iTextSharp.text.pdf.BaseFont
  bfR = iTextSharp.text.pdf.BaseFont.CreateFont("verdana.ttf", iTextSharp.text.pdf.BaseFont.IDENTITY_H, iTextSharp.text.pdf.BaseFont.EMBEDDED)

I'm using the IDENTITY_H property here so that support for other alphabets is enabled.




回答3:


The attribute PdfPTable has a property DefaultCell which you can set the defaults properties of your PdfPCell elements:

//C#
tableInstance.DefaultCell.Phrase = new Phrase() { Font = yourFont };


来源:https://stackoverflow.com/questions/1374563/changing-font-size-of-pdfptable

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!