Export report
To control and customize report export in the Bold Reports® ASP.NET Core Report Viewer, use its export events and properties. You can handle export progress, change export formats, hide export types, and set PDF, Word, Excel, and CSV options.
How do I show export progress in the Report Viewer?
To show progress information in the ASP.NET Core Report Viewer when the exporting process takes a long time to complete, use the export-progress-changed event.
- Set the
export-progress-changedevent in Report Viewer initialization. - Implement the function and replace the following code samples to show a custom message based on the progress stage.
The following code example demonstrates export event handling in the Report Viewer on the 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>How do I change the Excel and Word export format?
To change the default Excel and Word export file format in the ASP.NET Core Report Viewer, use the ExcelFormat and WordFormat properties.
The following code example demonstrates how to change the Excel and Word export format in the Report Viewer on the 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 the Excel and Word export format in the Report Viewer on the 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();
}How do I hide a specific export type for a report?
To hide a specific export type, show or hide the default export types available in the ASP.NET Core Report Viewer using the ExportOptions property.
The following code example demonstrates how to hide a specific export type for the report in the Report Viewer on the 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 a specific export type for the report in the Report Viewer on the 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();
}PDF export options
The PDFOptions class provides properties to manage PDF export behaviors in the ASP.NET Core Report Viewer. Set the properties in the OnInitReportOptions method of the Web API service.
How do I export reports with complex scripts?
To export reports with complex scripts from the ASP.NET Core Report Viewer, set the ComplexScript property of the PDFOptions instance to true.
public void OnInitReportOptions(ReportViewerOptions reportOption)
{
reportOption.ReportModel.PDFOptions = new BoldReports.Writer.PDFOptions()
{
EnableComplexScript = true
};
}
PDF conformance
To export the report as a PDF/A-1b document from the ASP.NET Core Report Viewer, specify 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
};
}
How do I add custom fonts to an exported PDF document?
To add custom fonts to a PDF document exported from the ASP.NET Core Report Viewer, add the font streams to the Fonts property in PDFOptions.
If a font used in the report is not installed or not available in the local system, you must add the font stream to the
Fontsproperty.
Follow these points when you add new fonts:
- Key should be same as in
FontFamilyelement of the report item. - Key is case sensitive, so the casing must match
FontFamily. - To add streams for different font styles and weights, consider the following:
- Key should be in the format of
{fontname} {weight} {style}. For exampleRoboto Light Italic. - Use only single white space between font name, weight, and style.
- When
FontStyleis set toNormalthen use style asRegular. For exampleRoboto Light Regular.
- Key should be in the format of
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) }
}
};
}The preceding code loads the
ttfstreams for theRobotofont with different style and weight combinations.
Word export options
The WordOptions class provides properties to manage Word document export behaviors in the ASP.NET Core Report Viewer.
Word document type
To save the report to the required Word document version, set the FormatType property.
reportOption.ReportModel.WordOptions = new BoldReports.Writer.WordOptions()
{
FormatType = BoldReports.Writer.WordFormatType.Docx
};Word document advance layout for merged cells
To eliminate tiny columns, rows, and merged cells, 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 the Word document auto merging behavior. A table in a Word document is not a stand-alone object. If you draw two tables one after another, they are automatically merged into a single table. To prevent this merging, add an empty paragraph between two tables.
How do I protect an exported Word document from editing?
To protect a Word document exported from the ASP.NET Core Report Viewer, restrict editing either with a password or without a 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
};Excel export options
The ExcelOptions class provides properties to manage Excel document export behaviors in the ASP.NET Core Report Viewer.
Excel document type
To save the report to the required Excel version, set the ExcelSaveType property.
reportOption.ReportModel.ExcelOptions = new BoldReports.Writer.ExcelOptions()
{
ExcelSaveType = BoldReports.Writer.ExcelVersion.Excel2013
};Excel document advance layout for merged cells
To eliminate tiny columns, rows, and merged cells for clear readability and data manipulation, set the LayoutOption to IgnoreCellMerge.
reportOption.ReportModel.ExcelOptions = new BoldReports.Writer.ExcelOptions()
{
LayoutOption = BoldReports.Writer.ExcelLayoutOptions.IgnoreCellMerge
};How do I protect an exported Excel document from editing?
To protect an Excel document exported from the ASP.NET Core Report Viewer, restrict 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
};CSV export options
The CsvOptions class lets you change the encoding, delimiters, qualifiers, extension, and line break of a CSV document exported from the ASP.NET Core Report Viewer.
reportOption.ReportModel.CsvOptions = new BoldReports.Writer.CsvOptions()
{
Encoding = System.Text.Encoding.Default,
FieldDelimiter = ",",
UseFormattedValues = false,
Qualifier = "#",
RecordDelimiter = "@",
SuppressLineBreaks = true,
FileExtension = ".txt"
};How do I password protect an exported document?
To protect an exported PDF, Word, Excel, or PowerPoint document from unauthorized users, encrypt the document with an encryption password in the ASP.NET Core Report Viewer. The following code snippet illustrates how to encrypt the exported document with a 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.
How do I change the file name of an exported report?
To change the file name of a report exported from the ASP.NET Core Report Viewer, use the FileName property.
public void OnInitReportOptions(ReportViewerOptions reportOption)
{
reportOption.ReportModel.ExportSettings = new BoldReports.Writer.ExportSettings()
{
FileName = "Invoice"
};
}How do I change the image quality in an exported report?
To change the image quality of data visualization items in a report exported from the ASP.NET Core Report Viewer, use the ImageQuality property.
public void OnInitReportOptions(ReportViewerOptions reportOption)
{
reportOption.ReportModel.ExportSettings = new BoldReports.Writer.ExportSettings()
{
ImageQuality = 4
};
}