we have provided the below option to export the data visualization report items
External Browser - Puppeteer
In .NET Framework it supports
net621
or above version only. To Download puppeteer package use below link.
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 |
PuppeteerSharp
package from NuGet Gallery
.wwwroot/Puppeteer
in your application.chrome-win
folder for Windows from the extracted location and paste into wwwroot/Puppeteer
folder in your application.BrowserTypes
Enum property to External
.CustomBrowserType
by inheriting the ExportSettings
class.ResourcePath
, Scripts
and DependentScripts
property in Report Writer
instance. The following code example demonstrates how to configure Puppeteer
in your ASP.NET Web Forms application.In this tutorial, the
product-line-sales.rdl
report is used, and it can be downloaded in this link.
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/9.1.7/scripts/v2.0/common/bold.reports.common.min.js",
"https://cdn.boldreports.com/9.1.7/scripts/v2.0/common/bold.reports.widgets.min.js",
//Report Viewer Script
"https://cdn.boldreports.com/9.1.7/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
Scripts
andDependent
scripts must be added to export the data visualization report items.
PhantomJS - Classic Tool
To download
PhantomJS
application and deploy it on your machine, you should accept its license terms on LICENSE and Third-Party document.
PhantomJS
for windows
here and for linux
here and extract the download file.PhantomJS
file from the extracted bin folder and paste into Resources/PhantomJS
folder in your application.UsePhantomJS
property to true
.PhantomJSPath
, Scripts
and DependentScripts
property in Report Writer
instance. The following code example demonstrates how to configure PhantomJS
in your ASP.NET Web Forms application.In this tutorial, the
product-line-sales.rdl
report is used, and it can be downloaded in this link.
protected void ExportButton_Click(object sender, EventArgs e)
{
string fileName = null;
WriterFormat format;
HttpContext httpContext = System.Web.HttpContext.Current;
BoldReports.Writer.ReportWriter writer = new BoldReports.Writer.ReportWriter();
writer.ReportPath = Server.MapPath("~/Resources/sales-order-detail.rdl");
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 = Server.MapPath("/Resources/PhantomJS");
writer.ExportResources.Scripts = new List<string>
{
//Report Viewer component dependent script
"https://cdn.boldreports.com/9.1.7/scripts/v2.0/common/bold.reports.common.min.js",
"https://cdn.boldreports.com/9.1.7/scripts/v2.0/common/bold.reports.widgets.min.js",
//Report Viewer Script
"https://cdn.boldreports.com/9.1.7/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 (this.ExportFormat.SelectedValue == "PDF")
{
fileName = "sales-order-detail.pdf";
format = WriterFormat.PDF;
}
else if (this.ExportFormat.SelectedValue == "Word")
{
fileName = "sales-order-detail.docx";
format = WriterFormat.Word;
}
else if (this.ExportFormat.SelectedValue == "Html")
{
fileName = "sales-order-detail.Html";
format = WriterFormat.HTML;
}
else if (this.ExportFormat.SelectedValue == "PPT")
{
fileName = "sales-order-detail.ppt";
format = WriterFormat.PPT;
}
else
{
fileName = "sales-order-detail.xlsx";
format = WriterFormat.Excel;
}
writer.Save(fileName, format, httpContext.Response);
}
}
The
Scripts
andDependent
scripts must be added to export the data visualization report items.