如何为 FastReport.Web 中的元素设置字体以便应用于 pdf 导出?

How to set font for elements in FastReport.Web so that applies on pdf export?

我正在为我的 dotnet 核心使用快速报告网络 application.I 有一个包含一些元素的报告。 这些元素使用客户端电脑上不存在的特殊字体

如果我在设计器中设置字体,只有在客户端电脑上安装该字体时它才会起作用。

我如何为这些元素设置字体,以便文本在预览和 pdf 导出时正确?

此外,我在 pdf 和打印中遇到了打印问题,例如分隔字符和无序数字和字母。(我的报告语言是波斯语,它是 rtl)

我的代码是:

在控制器中:

var webReport = new WebReport();
webReport.Report.RegisterData(some_data, "Data");
var file = System.IO.Path.Combine(_env.WebRootPath, "Reports\" + model.File);
webReport.Report.Load(file);
return View(webReport);

在视图中:

<div id="printBody" style="width:100%">
    @await Model.Render()
</div>

在此先感谢您的帮助。

目前,fastreport web 似乎不支持 rtl 语言的打印和 pdf 导出的完整功能。所以我做了以下场景,我得到了可接受的结果。

1 - 将报告导出到图像

2 - 使用 iTextSharp

将准备好的图像转换为 pdf

3 - Return 准备了 pdf

这样客户端就不用安装字体了

我使用了以下函数:

public FileStreamResult ReportToPdf(WebReport rpt, IWebHostEnvironment _env)
    {

        rpt.Report.Prepare();
        using (ImageExport image = new ImageExport())
        {
            //Convert to image
            image.ImageFormat = ImageExportFormat.Jpeg;
            image.JpegQuality = 100; // quality
            image.Resolution = 250; // resolution 
            image.SeparateFiles = true;
            var fname = "";
            var no = new Random().Next(10, 90000000);
            fname = $"f_{DateTime.Now.Ticks}_{no}";
            rpt.Report.Export(image, _env.WebRootPath + "\Exports\" + fname + ".jpg");


            // Convert to pdf
            MemoryStream workStream = new MemoryStream();
            Document document = new Document();
            PdfWriter.GetInstance(document, workStream).CloseStream = false;
            document.SetMargins(0, 0, 0, 0);

            document.SetPageSize(PageSize.A4);
            document.Open();
            float documentWidth = document.PageSize.Width;
            float documentHeight = document.PageSize.Height;

            foreach (var path in image.GeneratedFiles)
            {
                var imagex = Image.GetInstance(System.IO.File.ReadAllBytes(path));
                imagex.ScaleToFit(documentWidth, documentHeight);
                document.Add(imagex);

                try
                {
                    System.IO.File.Delete(path);
                }
                catch { }
            }
            document.Close();
            byte[] byteInfo = workStream.ToArray();
            workStream.Write(byteInfo, 0, byteInfo.Length);
            workStream.Position = 0;

            return new FileStreamResult(workStream, "application/pdf");
        }
    }