I am using fast report web for my dotnet core application.I have a report that contains some elements. These elements use a special font that is not exists on client's device.
If i set font in designer , it will works only when that font installed on client's device.
How can i set font for this elements , such that texts be correct in preview and pdf export?
Moreover i have printing problems such as separated characters and disordered numbers and letters in pdf and print.(My reports language is Persian and it is rtl)
My code is:
In controler :
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);
In view:
<div id="printBody" style="width:100%">
@await Model.Render()
</div>
Thanks in advance for any help.
It seems currently , fastreport web doesn't support full features for printing and pdf exporting for rtl languages. So i did following scenario and i got acceptable result.
1 - Export report to image
2 - Convert prepared image to pdf using iTextSharp
3 - Return prepared pdf
By so there is no need to install font on client device.
I used following function:
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");
}
}