如何设置 pdfptable 的字体?
问问题
22289 次
3 回答
6
创建短语时必须在每个单元格中设置字体:
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)
于 2009-09-03T16:44:24.227 回答
2
您需要创建一个与 iTextSharp 中的常规字体对象略有不同的“基本字体”对象。您将字体分配给为 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)
我在这里使用 IDENTITY_H 属性,以便启用对其他字母的支持。
于 2009-09-03T16:46:50.790 回答
2
属性 PdfPTable 有一个属性 DefaultCell,您可以设置 PdfPCell 元素的默认属性:
//C#
tableInstance.DefaultCell.Phrase = new Phrase() { Font = yourFont };
于 2012-05-09T18:06:11.630 回答