vb.net 更改pdfptable的字体大小

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1374563/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 14:23:37  来源:igfitidea点击:

Changing font size of pdfptable

vb.netitext

提问by l--''''''---------''''''''''''

How do I set the font for a pdfptable?

如何设置 pdfptable 的字体?

回答by Jason

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)

回答by Stewbob

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.

您需要创建一个“基本字体”对象,它与 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)

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

我在这里使用 IDENTITY_H 属性,以便启用对其他字母的支持。

回答by fabriciorissetto

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

属性 PdfPTable 有一个属性 DefaultCell ,您可以设置 PdfPCell 元素的默认属性:

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