The Report Viewer provides events and properties to control and customize the report exporting functionality.
You can show the progress information, when the exporting process takes long time to complete using the export-progress-changed
event.
export-progress-changed
event in Report Viewer initialization.The following code example demonstrates how to export event handling in the Report Viewer at client side.
<bold-report-viewer id="viewer" report-service-url="/api/ReportViewer" processing-mode="Remote" export-progress-changed="onExportProgressChanged">
</bold-report-viewer>
<script type="text/javascript">
function onExportProgressChanged(args) {
if (args.stage === "beginExport") {
console.log(args.stage);
args.format =
$('#viewer').ejWaitingPopup({ showOnInit: true, cssClass: "customStyle", text: "Preparing exporting document.. Please wait..." });
}
else if (args.stage === "exportStarted") {
console.log(args.stage);
var popupObj1 = $('#viewer').data('ejWaitingPopup');
popupObj1.hide();
}
else if (args.stage === "preparation") {
console.log(args.stage);
console.log(args.format);
console.log(args.preparationStage);
if (args.format === "PDF" && args.preparationStage === "documentPreparation") {
console.log(args.totalPages);
console.log(args.currentPage);
if (args.totalPages > 1 && args.currentPage > 1) {
var progressPercentage = Math.floor((args.currentPage / args.totalPages) * 100);
if (progressPercentage > 0) {
var popupObj2 = $('#viewer').data('ejWaitingPopup');
popupObj2.setModel({ text: "Preparing exporting document.." + progressPercentage + " % completed.. Please wait..." });
}
}
}
}
args.handled = true;
}
</script>
Allows you change the default file format to any other file format using the ExcelFormat
and WordFormat
properties.
The following code example demonstrates how to change Excel and Word export format in the Report Viewer at client side.
<bold-report-viewer id="viewer" report-service-url="/api/ReportViewer" processing-mode="Remote" export-settings="ViewBag.exportSettings">
</bold-report-viewer>
The following code example demonstrates how to change Excel and Word export format in the Report Viewer at server side.
public ActionResult Index()
{
ViewBag.exportSettings = new BoldReports.Models.ReportViewer.ExportSettings();
ViewBag.exportSettings.ExcelFormat = BoldReports.ReportViewerEnums.ExcelFormats.Excel2013;
ViewBag.exportSettings.WordFormat = BoldReports.ReportViewerEnums.WordFormats.Word2013;
return View();
}
Show or hide the default export types available in the component using the ExportOptions
property.
The following code example demonstrates how to hide specific export type to the report in the Report Viewer at client side.
<bold-report-viewer id="viewer" report-service-url="/api/ReportViewer" processing-mode="Remote" export-settings="ViewBag.exportSettings">
</bold-report-viewer>
The following code example demonstrates how to hide specific export type to the report in the Report Viewer at server side.
public ActionResult Index()
{
ViewBag.exportSettings = new BoldReports.Models.ReportViewer.ExportSettings();
ViewBag.exportSettings.ExportOptions = BoldReports.ReportViewerEnums.ExportOptions.All
& ~BoldReports.ReportViewerEnums.ExportOptions.Pdf;
return View();
}
The PDFOptions
provides properties to manage PDF export behaviors. You should set the properties in the OnInitReportOptions
method of the Web API service.
To export reports with the complex scripts, set the ComplexScript
property of PDFOptions
instance to true.
public void OnInitReportOptions(ReportViewerOptions reportOption)
{
reportOption.ReportModel.PDFOptions = new BoldReports.Writer.PDFOptions()
{
EnableComplexScript = true
};
}
You can export the report as a PDF/A-1b
document by specifying the PdfConformanceLevel.Pdf_A1B
conformance level in the PdfConformanceLevel
property.
public void OnInitReportOptions(ReportViewerOptions reportOption)
{
reportOption.ReportModel.PDFOptions = new BoldReports.Writer.PDFOptions()
{
PdfConformanceLevel = Syncfusion.Pdf.PdfConformanceLevel.Pdf_A1B
};
}
This section explains the steps to add custom fonts to the PDF exported document. The Report Viewer provides Fonts
property in PDFOptions
to add the new fonts.
Any fonts used in the report that is not installed or not available in the local system, then you must add the font stream to
Fonts
property.
The following points should be followed while adding new fonts:
FontFamily
element of the report item.FontFamily
.{fontname} {weight} {style}
. For example Roboto Light Italic
.FontStyle
is set to Normal
then use style as Regular
. For example Roboto Light Regular
.public void OnInitReportOptions(ReportViewerOptions reportOption)
{
reportOption.ReportModel.PDFOptions = new BoldReports.Writer.PDFOptions()
{
//Load missing font stream
Fonts = new Dictionary<string, System.IO.Stream>
{
{ "Roboto", new FileStream(basePath + @"\fonts\roboto\Roboto.ttf", FileMode.Open, FileAccess.Read) },
{ "Roboto Bold", new FileStream(basePath + @"\fonts\roboto\Roboto-Bold.ttf", FileMode.Open, FileAccess.Read) },
{ "Roboto Bold Regular", new FileStream(basePath + @"\fonts\roboto\Roboto-Bold.ttf", FileMode.Open, FileAccess.Read) },
{ "Roboto Light Italic", new FileStream(basePath + @"\fonts\roboto\Roboto-Light-Italic.ttf", FileMode.Open, FileAccess.Read) },
{ "Roboto Thin", new FileStream(basePath + @"\fonts\roboto\Roboto-Thin.ttf", FileMode.Open, FileAccess.Read) }
}
};
}
In the above code, loaded the
ttf
streams forRoboto
font with different style and weight combinations.
The WordOptions
provides properties to manage Word document export behaviors.
You can save the report to the required document version by setting the FormatType
property.
reportOption.ReportModel.WordOptions = new BoldReports.Writer.WordOptions()
{
FormatType = BoldReports.Writer.WordFormatType.Docx
};
Eliminate the tiny columns, rows, merged cells, and render the word document elements without nested grid layout by setting the LayoutOption
to TopLevel
. The ParagraphSpacing
is the distance value added between two elements in the document.
reportOption.ReportModel.WordOptions = new BoldReports.Writer.WordOptions()
{
LayoutOption = BoldReports.Writer.WordLayoutOptions.TopLevel,
ParagraphSpacing = new BoldReports.Writer.ParagraphSpacing()
{
Bottom = 0.5f,
Top = 0.5f
}
};
A paragraph element is inserted between two tables in the exported document to overcome word document auto merging behavior. The table in the word document is not a stand-alone object. If you draw two tables one after another, it will automatically get merged into a single table. To prevent this merging, add an empty paragraph between two tables.
You can restrict a Word document from editing either by providing a password or without password. The following are the types of protection:
AllowOnlyComments
: Adds or modifies only the comments in the Word document.AllowOnlyFormFields
: Modifies the form field values in the Word document.AllowOnlyRevisions
: Accepts or rejects the revisions in the Word document.AllowOnlyReading
: Views the content only in the Word document.NoProtection
: Accesses or edits the Word document contents as normally. reportOption.ReportModel.WordOptions = new BoldReports.Writer.WordOptions()
{
ProtectionType = Syncfusion.DocIO.ProtectionType.AllowOnlyReading
};
The ExcelOptions
provides properties to manage Excel document export behaviors.
You can save the report to the required excel version by setting the ExcelSaveType
property.
reportOption.ReportModel.ExcelOptions = new BoldReports.Writer.ExcelOptions()
{
ExcelSaveType = BoldReports.Writer.ExcelVersion.Excel2013
};
Eliminate the tiny columns, rows, and merged cells to provide clear readability and perform data manipulations by setting the LayoutOption
to IgnoreCellMerge
.
reportOption.ReportModel.ExcelOptions = new BoldReports.Writer.ExcelOptions()
{
LayoutOption = BoldReports.Writer.ExcelLayoutOptions.IgnoreCellMerge
};
You can restrict the Excel document from editing either by providing the ExcelSheetProtection
or enabling the ReadOnlyRecommended
properties.
reportOption.ReportModel.ExcelOptions = new BoldReports.Writer.ExcelOptions()
{
ReadOnlyRecommended = true,
ExcelSheetProtection = Syncfusion.XlsIO.ExcelSheetProtection.DeletingColumns
};
The CsvOptions
allows you to change encoding, delimiters, qualifiers, extension, and line break of a CSV exported document.
reportOption.ReportModel.CsvOptions = new BoldReports.Writer.CsvOptions()
{
Encoding = System.Text.Encoding.Default,
FieldDelimiter = ",",
UseFormattedValues = false,
Qualifier = "#",
RecordDelimiter = "@",
SuppressLineBreaks = true,
FileExtension = ".txt"
};
Allows you protect the exported document such as PDF, Word, Excel, and PowerPoint from unauthorized users by encrypting the document using encryption password. The following code snippet illustrates how to encrypt the exported document with user-defined password.
public void OnInitReportOptions(ReportViewerOptions reportOption)
{
//PDF encryption
reportOption.ReportModel.PDFOptions = new BoldReports.Writer.PDFOptions();
reportOption.ReportModel.PDFOptions.Security = new Syncfusion.Pdf.Security.PdfSecurity()
{
UserPassword = "password"
};
//Word encryption
reportOption.ReportModel.WordOptions = new BoldReports.Writer.WordOptions()
{
EncryptionPassword = "password"
};
//Excel encryption
reportOption.ReportModel.ExcelOptions = new BoldReports.Writer.ExcelOptions()
{
PasswordToModify = "password",
PasswordToOpen = "password"
};
}
Password protection is not supported for HTML export format.
You can change the file name of report in export using the FileName
property.
public void OnInitReportOptions(ReportViewerOptions reportOption)
{
reportOption.ReportModel.ExportSettings = new BoldReports.Writer.ExportSettings()
{
FileName = "Invoice"
};
}
You can change image quality of data visualization items in report export using the ImageQuality
property.
public void OnInitReportOptions(ReportViewerOptions reportOption)
{
reportOption.ReportModel.ExportSettings = new BoldReports.Writer.ExportSettings()
{
ImageQuality = 4
};
}