.net-core - 如何为 FastReport.Web 中的元素设置字体以便应用于 pdf 导出?
问题描述
我正在为我的 dotnet 核心应用程序使用快速报告网络。我有一个包含一些元素的报告。 这些元素使用客户端 pc 上不存在的特殊字体。
如果我在设计器中设置字体,则仅当该字体安装在客户端 PC 上时才会起作用。
如何为这些元素设置字体,以便预览和 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");
}
}
推荐阅读
- react-native - 找不到 -lreact-native-jitsi-meet ios 的库
- python - 使用 typing.Literal 引发 TypeError
- kernel - 并行缩减无法正常工作
- spring-boot - SpringBoot 健康响应差异
- spring - 如果将弹簧数据弹性添加到类路径,为什么 Spting 应用程序在执行后不会停止
- virtualization - 使用带有 PCI 直通的主 GPU 时,驱动程序未加载到来宾操作系统中
- javascript - 我想使用 javscript map 使数组独一无二——我正在使用 react 框架
- asp.net-core - Application Insights:控制台应用程序 HttpClient 关联不起作用
- css - 为什么 Am Chars 和弦图会切割标签文本?
- r - 如何根据 R 中的某些模式导入大量数据集