Stimulsoft NODE.JS教程:将字体添加到资源

本示例说明了如何加载字体文件,将其添加到 表资源以及呈现 表。

本示例说明了如何加载字体文件,将其添加到 表资源以及呈现 表。首先,您应该将Stimulsoft模块添加到项目中。为此,只需使用一个通用软件包,所有其他依赖项将自动加载:

var Stimulsoft = require('stimulsoft-reports-js');console.log("Stimulsoft Reports loaded");

接下来,创建一个新的StiReport对象,只需调用该对象的构造函数即可:

var report = new Stimulsoft.Report.StiReport();

现在,您应该加载字体文件并将其添加到 表资源中。为此专门设计了一个StiResource对象。该对象可以包含任何受支持的文件类型:数据、图像、字体、其他 告等。作为构造函数的参数,指定资源的名称和别名、资源的类型以及先前加载的字体。然后将其添加到资源集合中,一切就绪:

var fileContent = Stimulsoft.System.IO.File.getFile("Roboto-Black.ttf", true);var resource = new Stimulsoft.Report.Dictionary.StiResource(    "Roboto-Black", "Roboto-Black", false, Stimulsoft.Report.Dictionary.StiResourceType.FontTtf, fileContent);report.dictionary.resources.add(resource);

要检查字体的工作方式,请使用代码在 告页面中添加文本组件,然后在组件参数中使用此字体。为此,只需在font属性中指定资源名称, 表引擎将执行所有其他操作:

//Create textvar dataText = new Stimulsoft.Report.Components.StiText();dataText.clientRectangle = new Stimulsoft.System.Drawing.Rectangle(1, 1, 3, 2);dataText.text = "Sample Text";dataText.font = new Stimulsoft.System.Drawing.Font("Roboto-Black");dataText.border.side = Stimulsoft.Base.Drawing.StiBorderSides.All;page.components.add(dataText);

要呈现 表,请调用异步renderAsync()方法,该方法将执行所有必要的操作。另外,您可以在方法参数中指定一个回调函数,该函数将在渲染后调用:

// Renreding reportreport.renderAsync(function () {    console.log("Report rendered. Pages count: ", report.renderedPages.count);    // Saving rendered report to file    report.saveDocumentFile("Report.mdc");    console.log("Rendered report saved");});

在下面的屏幕截图中,您可以看到示例代码的结果:

Stimulsoft NODE.JS教程:将字体添加到资源

下载示例代码

产品介绍 | 下载试用 | 优惠活动 | 在线客服

标签:

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2020年1月13日
下一篇 2020年1月13日

相关推荐

发表回复

登录后才能评论