// following example to create pdf from report template which created using standalone designer template
public class ReportsController : ReportsControllerBase
{
readonly string reportsPath = string.Empty;
private IHostingEnvironment _hostingEnvironment;
public ReportsController(ConfigurationService configSvc)
{
this.reportsPath = Path.Combine("PathWhereReportTemplatesStored", "Reports"); //concatenate the path using the OS path delimiter.
this.ReportServiceConfiguration = new ReportServiceConfiguration
{
ReportingEngineConfiguration = configSvc.Configuration,
HostAppId = "Html5DemoAppCore",
Storage = new FileStorage(),
ReportResolver = new ReportTypeResolver()
.AddFallbackResolver(new ReportFileResolver(this.reportsPath)),
};
}
[HttpGet("reportlist")]
public IEnumerable<string> GetReports()
{
return Directory
.GetFiles(this.reportsPath)
.Select(path =>
Path.GetFileName(path));
}
//https://www.telerik.com/support/kb/reporting/styling-and-formatting-reports/details/exporting-a-report-to-pdf-programmatically
[HttpGet]
public IActionResult createPdf()
{
string fileName = "report_" + DateTime.Now.Ticks + ".pdf";
// https://docs.telerik.com/reporting/report-sources-viewers
var uriReportSource = new Telerik.Reporting.UriReportSource();
// Specifying an URL or a file path
uriReportSource.Uri = reportsPath + "\\reportTemplate.trdp"; // report template designed using standalone report designer
// Optional, pass param values to report, Adding the initial parameter values
uriReportSource.Parameters.Add(new Telerik.Reporting.Parameter("param1", "value"));
uriReportSource.Parameters.Add(new Telerik.Reporting.Parameter("param2", "value"));
ReportProcessor reportProcessor = new ReportProcessor();
RenderingResult result = reportProcessor.RenderReport("PDF", uriReportSource, null);
// to write pdf on disc, omit if not required
using (FileStream fs = new FileStream("PathWhereYouWantToWritePdfOnDisk" + "pdfName.pdf", FileMode.Create))
{
fs.Write(result.DocumentBytes, 0, result.DocumentBytes.Length);
}
return File(result.DocumentBytes, "application/pdf", fileName); // in case , user clicks on link and download report
}
}