此示例演示如何使用 PdfFont 类使用不同的字体绘制文本。
开箱即用 PdfDocument 支持以下字体:Courier,Helvetica,Times,Symbol,ZapfDingbats。前三种字体各有四种字体,“正常”,“粗体”,“倾斜”和“粗斜”。这为我们提供了一组称为“14标准PDF字体”的字体。
PdfFont 类描述了一个特定的字体,它的构造函数接受以下参数:
以下实例是PdfDocument方面的默认文档字体:
new wijmo.pdf.PdfFont("times", 10, "normal", "normal");
在 PdfDocument 中,可以通过两种方式指定字体:
通过将PdfFont实例直接传递给** drawText 作为 options.font **属性。
doc.drawText("Lorem", null, null, { font: new wijmo.pdf.PdfFont("times", 10, "normal", "bold") });
首先使用 ** doc.setFont** 方法更改默认文档字体。 如果你调用 drawText 方法而不传递字体,它将被使用。 当需要绘制大量具有相同字体的文本时,此方法很有用。
doc.setFont(new wijmo.pdf.PdfFont("times", 10, "normal", "bold")); doc.drawText("Lorem");
如果找不到具有确切给定样式和权重属性的字体,则将使用最接近的注册字体。
此示例演示如何使用 drawText 和 doc.setFont 方法使用不同的字体绘制文本。