Resizing pdfptable font

How do I set the font for pdfptable?

+2


source to share


3 answers


You must set the font in each cell when creating the 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)

      

+6


source


You need to create a "Base Font" object that is slightly different from the regular font object in iTextSharp. You are assigning a 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 am using the IDENTITY_H property here so support for other alphabets is supported.

+2


source


The PdfPTable attribute has a DefaultCell property that you can set default properties for your PdfPCell items:

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

      

+2


source







All Articles