HTML5 Viewer : Export using Custom Name
We already have had blogs discussing about how to use ActiveReports in HTML5 Viewer. Also does the documentation shows how you can customize, localize and deploy HTML5 viewer. Moving one step forward, in this blog we will discuss how can we export the report (loaded in HTML5 Viewer) and save it with any custom name than the default 'ActiveReports.extension' The default behavior is that whenever the 'SaveAs' dropdown is clicked and the respective export option selected, the exported report file gets saved with the default name in the following manner : ActiveReports.doc ActiveReports.pdf Let's consider a case wherein you wish to export the report to PDF format and save it with the name of the report loaded in the viewer. In order to achieve this implementation one needs to follow the under-mentioned steps : 1. Hide the default 'SaveAs’ dropdown 2. Add a custom Export Button and handle it’s click event 3. In this click event export the Loaded Report is to PDF format (you may add other export formats too) 4. While exporting the Report, assign the custom name (the name of the loaded report in this case) to the exported PDF file.
$('#ExportToPdf’).bind('click’, function (ev)
{
viewer.export('Pdf’, downloadReport, true, { FileName: viewer.option("report").id });
});
PS : The Export function of HTML5 Veiwer does not download the report, it just exports it in selected format and returns uri of prepared document. Hence, to get the download the exported file of the report with the custom name, we need to write the CallBack function of the Export Function in the following manner :
//function downloads report from specified uri</pre>
var downloadReport = function (uri)
{
var newWin = null;
// try to open uri in new window
try
{
newWin = window.open(uri);
}
catch (e)
{
}
// if browser rejects opening new window, open uri in current one
if (!newWin)
{
window.location = uri;
}
};
For complete implementation, please download the sample from here.