Export Data Visualization in Core Environment
To export data visualization report items with the Bold Reports® ASP.NET Core Report Writer, use an external browser (Puppeteer or Playwright) or PhantomJS. The Report Writer uses the WebBrowser Control to export data visualization report items to PDF, PPT, Word, Excel, and HTML file formats, but the WebBrowser is not supported in the Core environment. Use one of the following methods to export the report.
Note:
Puppeteer: Supports the .NET Core framework and most Linux distributions used in Kubernetes, including Ubuntu. Puppeteer does not support Azure environments. For Azure on Linux in windows, usePlaywright.Playwright: Supports the .NET Core framework.PhantomJS: Supports the .NET Core framework, but PhantomJS is no longer actively maintained.
External Browser - Puppeteer
To export data visualization report items with Puppeteer in the ASP.NET Core Report Writer, download the Chromium package for your operating system and configure PuppeteerSharp in your application.
In .NET Core it supports
ASP.NET Core 2.1or above version only. To download the Puppeteer package, use the following links.
| Operating System | Download Link |
|---|---|
Windows 32-bit |
https://storage.googleapis.com/chromium-browser-snapshots/Win/901912/chrome-win.zip |
Windows 64-bit |
https://storage.googleapis.com/chromium-browser-snapshots/Win_x64/901912/chrome-win.zip |
linux |
https://storage.googleapis.com/chromium-browser-snapshots/Linux_x64/901912/chrome-linux.zip |
- Open the Report Writer application and install the
PuppeteerSharppackage fromNuGet Gallery. - Create the
wwwroot/Puppeteerfolder in your application. - Copy the
chrome-winfolder for Windows orchrome-linuxfolder for Linux from the extracted location of puppeteer package and paste intowwwroot/Puppeteerfolder in your application. - Open the Report Writer application Web API file.
- Set the
BrowserTypesEnum property toExternal. - Create and initialize
CustomBrowserTypeby inheriting theExportSettingsclass. - Set the
ResourcePath,ScriptsandDependentScriptsproperty inReport Writerinstance. The following code example demonstrates how to configurePuppeteerin your ASP.NET Core application.
In this tutorial, the
product-line-sales.rdlreport is used. You can download it from the product line sales sample report download.
public class HomeController : Controller
{
// IWebHostEnvironment used with sample to get the application data from wwwroot.
private Microsoft.AspNetCore.Hosting.IWebHostEnvironment _hostingEnvironment;
// IWebHostEnvironment initialized with controller to get the data from application data folder.
public HomeController(Microsoft.AspNetCore.Hosting.IWebHostEnvironment hostingEnvironment)
{
_hostingEnvironment = hostingEnvironment;
}
public IActionResult Index()
{
return View();
}
[HttpPost]
public IActionResult Export(string writerFormat)
{
string fileName = null;
WriterFormat format;
string basePath = _hostingEnvironment.WebRootPath;
// Here, we have loaded the sample report from application the folder wwwroot.
FileStream inputStream = new FileStream(basePath + @"\Resources\product-line-sales.rdl", FileMode.Open, FileAccess.Read);
MemoryStream reportStream = new MemoryStream();
inputStream.CopyTo(reportStream);
reportStream.Position = 0;
inputStream.Close();
BoldReports.Writer.ReportWriter writer = new BoldReports.Writer.ReportWriter();
// Puppeteer Option to export the data visualization report items.
writer.ExportResources.BrowserType = ExportResources.BrowserTypes.External;
writer.ExportResources.ResourcePath = basePath + @"/Puppeteer/";
// Initialize the class for puppeteer
writer.ExportSettings = new customBrowsertype(writer.ExportResources.ResourcePath);
writer.ExportResources.Scripts = new List<string>
{
//Report Viewer component dependent script
"https://cdn.boldreports.com/15.1.10/scripts/v2.0/common/bold.reports.common.min.js",
"https://cdn.boldreports.com/15.1.10/scripts/v2.0/common/bold.reports.widgets.min.js",
//Report Viewer Script
"https://cdn.boldreports.com/15.1.10/scripts/v2.0/bold.report-viewer.min.js"
};
writer.ExportResources.DependentScripts = new List<string>
{
"https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"
};
if (writerFormat == "PDF")
{
fileName = "ProductLineSales.pdf";
format = WriterFormat.PDF;
}
else if (writerFormat == "Word")
{
fileName = "ProductLineSales.docx";
format = WriterFormat.Word;
}
else if (writerFormat == "CSV")
{
fileName = "ProductLineSales.CSV";
format = WriterFormat.CSV;
}
else
{
fileName = "ProductLineSales.xlsx";
format = WriterFormat.Excel;
}
writer.LoadReport(reportStream);
MemoryStream memoryStream = new MemoryStream();
writer.Save(memoryStream, format);
// Download the generated document from client.
memoryStream.Position = 0;
FileStreamResult fileStreamResult = new FileStreamResult(memoryStream, "application/pdf");
fileStreamResult.FileDownloadName = fileName;
return fileStreamResult;
}
// Add the class to override the method for puppeteer
public class CustomBrowserType : ExportSettings
{
private string puppeteerPath;
public CustomBrowserType(string path)
{
puppeteerPath = path;
}
// Can be used to rendered html data visualization from the given url and convert the image to base 64 string by using external browser
public override string GetImageFromHTML(string url)
{
return LaunchPuppeteer(url).Result;
}
// Can be used to convert the image from Puppeteer
public async Task<string> LaunchPuppeteer(string url)
{
// Assigned the chrome.exe path to the puppeteer
await using var browser = await Puppeteer.LaunchAsync(new LaunchOptions { Headless = true, ExecutablePath = puppeteerPath + @"chrome-win/chrome.exe"});
await using var page = await browser.NewPageAsync();
await page.GoToAsync(url);
return await page.WaitForSelectorAsync("#imagejsonData").Result.GetPropertyAsync("innerText").Result.JsonValueAsync<string>();
}
}
}The
ScriptsandDependentscripts must be added to export the data visualization report items.
External Browser - Playwright
To export data visualization report items with Playwright in the ASP.NET Core Report Writer, download the Chromium package for your operating system and configure the Microsoft.Playwright package in your application.
In .NET Core it supports
ASP.NET Core 2.1or above versions only.
| Operating System | Download Link |
|---|---|
Windows 32-bit |
https://storage.googleapis.com/chromium-browser-snapshots/Win/901912/chrome-win.zip |
Windows 64-bit |
https://storage.googleapis.com/chromium-browser-snapshots/Win_x64/901912/chrome-win.zip |
linux |
https://storage.googleapis.com/chromium-browser-snapshots/Linux_x64/901912/chrome-linux.zip |
- Open the Report Writer application and install the
Microsoft. Playwrightpackage from theNuGet Gallery. - Create the following folder
wwwroot/Playwrightin your application. - Copy the
chrome-winfolder for Windows orchrome-linuxfolder for Linux from the extracted location of playwright package and paste intowwwroot/Playwrightfolder in your application. - Open the Web API file in the Report Writer application.
- Set the
BrowserTypesenum property toExternal. - Create and initialize a
HeadlessBrowserby inheriting from theExportSettingsclass. - Set the
ResourcePath,Scripts, andDependentScriptsproperties in theReport Writerinstance. The following code example demonstrates how to configurePlaywrightin your ASP.NET Core application.
In this tutorial, the
product-line-sales.rdlreport is used. You can download it from the product line sales sample report download.
public class HomeController : Controller
{
// IWebHostEnvironment is used in this example to retrieve application data from wwwroot.
private Microsoft.AspNetCore.Hosting.IWebHostEnvironment _hostingEnvironment;
// IWebHostEnvironment is initialized in the controller to access data from the application data folder
public HomeController(Microsoft.AspNetCore.Hosting.IWebHostEnvironment hostingEnvironment)
{
_hostingEnvironment = hostingEnvironment;
}
public IActionResult Index()
{
return View();
}
[HttpPost]
public IActionResult Export(string writerFormat)
{
string fileName = null;
WriterFormat format;
string basePath = _hostingEnvironment.WebRootPath;
// Load the sample report from the application's wwwroot folder.
FileStream inputStream = new FileStream(basePath + @"/Resources/product-line-sales.rdl", FileMode.Open, FileAccess.Read);
MemoryStream reportStream = new MemoryStream();
inputStream.CopyTo(reportStream);
reportStream.Position = 0;
inputStream.Close();
BoldReports.Writer.ReportWriter writer = new BoldReports.Writer.ReportWriter();
writer.ExportResources.BrowserType = ExportResources.BrowserTypes.External;
writer.ExportResources.ResourcePath = Path.Combine(basePath, "Playwright");
writer.ExportSettings = new CustomBrowserType(writer.ExportResources.ResourcePath);
writer.ExportResources.Scripts = new List<string>
{
//Report Viewer component dependent script
"https://cdn.boldreports.com/15.1.10/scripts/v2.0/common/bold.reports.common.min.js",
"https://cdn.boldreports.com/15.1.10/scripts/v2.0/common/bold.reports.widgets.min.js",
//Report Viewer Script
"https://cdn.boldreports.com/15.1.10/scripts/v2.0/bold.report-viewer.min.js"
};
writer.ExportResources.DependentScripts = new List<string>
{
"https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"
};
if (writerFormat == "PDF")
{
fileName = "ProductLineSales.pdf";
format = WriterFormat.PDF;
}
else if (writerFormat == "Word")
{
fileName = "ProductLineSales.docx";
format = WriterFormat.Word;
}
else if (writerFormat == "CSV")
{
fileName = "ProductLineSales.CSV";
format = WriterFormat.CSV;
}
else
{
fileName = "ProductLineSales.xlsx";
format = WriterFormat.Excel;
}
writer.LoadReport(reportStream);
MemoryStream memoryStream = new MemoryStream();
writer.Save(memoryStream, format);
// Download the generated document from client.
memoryStream.Position = 0;
FileStreamResult fileStreamResult = new FileStreamResult(memoryStream, "application/pdf");
fileStreamResult.FileDownloadName = fileName;
return fileStreamResult;
}
public class CustomBrowserType : ExportSettings
{
private readonly string _resourcePath;
public CustomBrowserType(string resourcePath)
{
_resourcePath = resourcePath;
}
public override string GetImageFromHTML(string url)
{
return GetImageFromHtmlAsync(url).GetAwaiter().GetResult();
}
private async Task<string> GetImageFromHtmlAsync(string url)
{
return await RenderWithPlaywrightAsync(url);
}
private async Task<string> RenderWithPlaywrightAsync(string url)
{
using var playwright = await Playwright.CreateAsync();
var chromiumPath = Path.Combine(_resourcePath, "chrome-win", "chrome.exe");
await using var browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions
{
Headless = true,
ExecutablePath = chromiumPath
});
var context = await browser.NewContextAsync();
var page = await context.NewPageAsync();
await page.GotoAsync(url);
await page.WaitForSelectorAsync("#imagejsonData");
return await page.Locator("#imagejsonData").InnerTextAsync();
}
}
}The
ScriptsandDependentscripts must be added to export the data visualization report items.
PhantomJS - Classic Tool
To export data visualization report items with PhantomJS in the ASP.NET Core Report Writer, deploy the PhantomJS application in your application folder and set the UsePhantomJS property to true.
It supports
ASP.NET Core 2.1or above versions only. To downloadPhantomJSapplication and deploy it on your machine, you should accept its license terms on LICENSE and Third-Party document.
- Download
PhantomJSforwindowsorPhantomJSforlinuxand extract the downloaded file. - Copy the
PhantomJSfile from the extracted bin folder and paste intowwwroot/PhantomJSfolder in your application. - Open the Report Writer application Web API file.
- Set the
UsePhantomJSproperty totrue. - Set the
PhantomJSPath,ScriptsandDependentScriptsproperty inReport Writerinstance. The following code example demonstrates how to configurePhantomJSin your ASP.NET Core application.
In this tutorial, the
product-line-sales.rdlreport is used. You can download it from the product line sales sample report download.
public class HomeController : Controller
{
// IWebHostEnvironment used with sample to get the application data from wwwroot.
private Microsoft.AspNetCore.Hosting.IWebHostEnvironment _hostingEnvironment;
// IWebHostEnvironment initialized with controller to get the data from application data folder.
public HomeController(Microsoft.AspNetCore.Hosting.IWebHostEnvironment hostingEnvironment)
{
_hostingEnvironment = hostingEnvironment;
}
public IActionResult Index()
{
return View();
}
[HttpPost]
public IActionResult Export(string writerFormat)
{
string fileName = null;
WriterFormat format;
string basePath = _hostingEnvironment.WebRootPath;
// Here, we have loaded the sample report from application the folder wwwroot.
FileStream inputStream = new FileStream(basePath + @"\Resources\product-line-sales.rdl", FileMode.Open, FileAccess.Read);
MemoryStream reportStream = new MemoryStream();
inputStream.CopyTo(reportStream);
reportStream.Position = 0;
inputStream.Close();
BoldReports.Writer.ReportWriter writer = new BoldReports.Writer.ReportWriter();
// PhantomJS Option to export the data visualization report items.
writer.ExportResources.UsePhantomJS = true;
// Set the IncludeText property to true, when text not displayed in the data visualization images.
writer.ExportResources.IncludeText = true;
writer.ExportResources.PhantomJSPath = basePath + @"\PhantomJS\";
writer.ExportResources.Scripts = new List<string>
{
//Report Viewer component dependent script
"https://cdn.boldreports.com/15.1.10/scripts/v2.0/common/bold.reports.common.min.js",
"https://cdn.boldreports.com/15.1.10/scripts/v2.0/common/bold.reports.widgets.min.js",
//Report Viewer Script
"https://cdn.boldreports.com/15.1.10/scripts/v2.0/bold.report-viewer.min.js"
};
writer.ExportResources.DependentScripts = new List<string>
{
"https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"
};
if (writerFormat == "PDF")
{
fileName = "ProductLineSales.pdf";
format = WriterFormat.PDF;
}
else if (writerFormat == "Word")
{
fileName = "ProductLineSales.docx";
format = WriterFormat.Word;
}
else if (writerFormat == "CSV")
{
fileName = "ProductLineSales.CSV";
format = WriterFormat.CSV;
}
else
{
fileName = "ProductLineSales.xlsx";
format = WriterFormat.Excel;
}
writer.LoadReport(reportStream);
MemoryStream memoryStream = new MemoryStream();
writer.Save(memoryStream, format);
// Download the generated document from client.
memoryStream.Position = 0;
FileStreamResult fileStreamResult = new FileStreamResult(memoryStream, "application/pdf");
fileStreamResult.FileDownloadName = fileName;
return fileStreamResult;
}
}The
ScriptsandDependentscripts must be added to export the data visualization report items.