是否可以使用ASP.NET Core呈现.rdlc
报告?目前,如果我的目标是.NET Framework而不是.NET Core,这似乎是可能的。
我不需要报表查看器我只需要将.rdlc
报表的结果呈现为字节数组。
您可以将rdlc渲染为字节数组。请查看我前一段时间问过的相关问题。 RDLC Local report viewer for ASP.NET Core and Angular(>2.0)。
最终,对该线程的创造性讨论产生了一个角度包(https://www.npmjs.com/package/ng2-pdfjs-viewer - Disclosure;我是作者),在客户端具有可消耗的rdlc字节数组功能。当然,您可以选择另一个javascript库来显示字节数组,而不是此包。
角度的简单用法就是这样。请注意,即使您使用普通的js或其他框架,大多数代码也可以重用。
以下代码演示
1.在aspnet核心操作方法(在服务器端)上使用RDLC报告查看器控件吐出字节数组,并使用http通过线路发送。 (代码在C#中) 2.将响应的字节数组处理成blob对象(Js) 3.将blob对象输入ng2-pdfjs-viewer。 4. ng2-pdfjs-viewer内部使用Mozilla的PDFJS来完成在浏览器上显示PDF的壮举。 (仅供参考。我从ng2-pdfjs-viewer包中提供的样本中获取代码。如果您使用的是其他库或普通javascript,请替换步骤3和4)
<!-- your.component.html -->
<button (click)="showPdf();">Show</button>
<div style="width: 800px; height: 400px">
<ng2-pdfjs-viewer #pdfViewer></ng2-pdfjs-viewer>
</div>
export class MyComponent implements OnInit {
@ViewChild('pdfViewer') pdfViewer
...
private downloadFile(url: string): any {
return this.http.get(url, { responseType: ResponseContentType.Blob }).map(
(res) => {
return new Blob([res.blob()], { type: "application/pdf" });
});
}
public showPdf() {
let url = "http://localhost/api/GetMyPdf";
this.downloadFile(url).subscribe(
(res) => {
this.pdfViewer.pdfSrc = res; // <---- pdfSrc can be Blob or Uint8Array
this.pdfViewer.refresh(); // Ask pdf viewer to load/reresh pdf
}
);
}
[HttpGet]
[Route("MyReport")]
public IActionResult GetReport()
{
var reportViewer = new ReportViewer {ProcessingMode = ProcessingMode.Local};
reportViewer.LocalReport.ReportPath = "Reports/MyReport.rdlc";
reportViewer.LocalReport.DataSources.Add(new ReportDataSource("NameOfDataSource1", reportObjectList1));
reportViewer.LocalReport.DataSources.Add(new ReportDataSource("NameOfDataSource2", reportObjectList1));
Warning[] warnings;
string[] streamids;
string mimeType;
string encoding;
string extension;
var bytes = reportViewer.LocalReport.Render("application/pdf", null, out mimeType, out encoding, out extension, out streamids, out warnings);
return File(bytes, "application/pdf")
}
当前使用.NET核心(没有完整的.NET Framework)呈现客户端RDLC报告的唯一方法是使用付费的Syncfusion解决方案。我测试了跟踪版本,效果很好。也可以使用ASP .NET Core(没有任何第三方工具)呈现服务器托管的RDL报告 - 不理想,因为我必须将许多RDLC报告迁移到RDL - Muaddib878 2分钟前编辑
您无法使用.rdlc作为字节数组在.NET Core中呈现.rdlc报告。