tha bot
Nov 1, 2021

.Net Core ใช้งาน Report Viewer แปลงออกมาเป็น PDF

เริ่มต้นด้วยการลง Microsoft.CodeAnalysis.CSharp.Workspaces 3.6.0 ต้องใช้ Version นี้เท่านั้นนะครับอย่าใช้ Version ล่าสุด ด้วย NuGet

ติดตั้ง ReportViewerCore.NETCore และ ReportViewerCore.WinForms ด้วย NuGet

เมื่อทำการลงเสร็จแล้วเราก็มาบรรเลงโค้ดกันได้เลยครับ

ServerReport report = new ServerReport();
report.ReportServerCredentials.NetworkCredentials = new NetworkCredential(“ReportUser”, “PasswordReportUser”, “”);
report.ReportServerUrl = new Uri(“http://127.0.0.1/ReportServer/");
report.ReportPath = “/ReportPath/ReportName”;
report.SetParameters(new[] { new ReportParameter(“IDData”, “12345678”) });
byte[] pdf = report.Render(“PDF”);
string base64Data = Convert.ToBase64String(pdf);

แค่นี้เราก็ได้รายงาน PDF จาก Reporting ที่ใช้งานกับ .NetCore ได้แล้วครับ หากต้องการข้อมูลเพิ่มเติมสามารถเข้าไปศึกษาต่อได้ที่ Link ด้านล่างนี้ได้เลยครับ
https://github.com/lkosson/reportviewercore