Hello,
I've created a report in standalone report designer with custom function. And saved it in trdp format.
I added a custom function and connected the assembly as described in this manual.
In the report editor, I see my function and use it, however when I try to use this report for printing, my function becomes unavailable.
public class BaseReportBook<TModel> : ReportBook, IDisposable
{
public virtual byte[] CreatePdf(TModel model, ReportTypeEnum reportType)
{
var reportPackager = new ReportPackager();
using var sourceStream = File.OpenRead(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Reports", reportType.GetDescription()));
var report = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream);
report.ItemDataBinding += new EventHandler((sender, e) => Report_ItemDataBinding(sender, e, model));
InstanceReportSource reportSource = new InstanceReportSource();
reportSource.ReportDocument = report;
ReportSources.Add(reportSource);
ReportProcessor reportProcessor = new ReportProcessor();
var instanceReport = new InstanceReportSource();
instanceReport.ReportDocument = this;
RenderingResult result = reportProcessor.RenderReport("PDF", instanceReport, null);
if (result.Errors.Length > 0)
throw new Exception(string.Join("\r\nError: ", result.Errors.Select(s => s.Message)));
return result.DocumentBytes;
}
private void Report_ItemDataBinding(object sender, EventArgs e, TModel model)
{
Telerik.Reporting.Processing.Report item = (Telerik.Reporting.Processing.Report)sender;
item.DataSource = model;
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
GC.SuppressFinalize(this);
GC.Collect();
}
}
reportType.GetDescription() returns the name of the report (e.g. test.trdp)
The report is successfully generated, but it does not see my function. Although they are in the same assembly.
When viewing the preview in the editor, the function works:
Here is the function itself:
public static class CustomFunctions
{
[Function(Category = "Images", Namespace = "Extension", Description = "Images")]
public static Image GetLogo() => new Bitmap(Properties.Resources.logo);
}