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



我正在为我的dotnet核心应用程序使用快速报告网络。我有一份报告包含一些内容。这些元素使用客户端设备上不存在的特殊字体

如果我在设计器中设置字体,则仅当该字体安装在客户端设备上时才有效。

如何为此元素设置字体,以使文本在预览和 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 - 返回准备好的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");
}
}

最新更新