In this article, we will show you how to generate Customer account statement, which is a Configurable business document, as a byte array in both original (Excel/Word) and PDF format.
Configurable business documents sit on top of SSRS and cannot be generated outside the SSRS report execution pipeline, because the SSRS framework is responsible for preparing the data and cleaning them up, after report run is completed. Actually, this is true only for pre-processed SSRS reports, where belong all main reports such as Sales invoice and Purchase order. For regular SSRS reports, including those which are query-based, e.g. Container contents report, there is no such limitation.
Printing a Configurable business document to memory can be useful, for example, if you want to deliver both PDF and Excel output formats to your customers. Let's say that you are using Docentric to produce nicely designed PDF documents when printing the Customer account statement report. But some customers demand to get the same data in an Excel document, to be able to process it as they used to.
For that reason, we created a handy helper class, DocERFormatGeneratorCBD, which can be invoked from SSRS or Docentric pipeline, to generate the currently executing SSRS report as a Configurable business document to memory. The only parameter you have to provide is the exact ER Format mapping GUID. In this example, we will generate the Excel document as a byte array for the given ER Format mapping of the executing Customer account statement report. The generation will take place in the Docentric DSP class for Customer account statement, but you can also do it anywhere from SSRS pipeline, after data preparation is completed and before the data clean-up is done.
In the example below, we extended the Docentric DSP class for Customer statement report (DocCustAccountStatementExtReportDSP) and invoked the CBD generator class (DocERFormatGeneratorCBD) in the extended overrideReportRunSettings() method.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
[ExtensionOf(classStr(DocCustAccountStatementExtReportDSP))] final class DocCustAccountStatementExtReportDSP_WE_Extension { public DocPlaceholderManager overrideReportRunSettings(DocReportRunContext _reportRunContext, boolean _replaceStandardPlaceholders) { DocPlaceholderManager placeholderManager = next overrideReportRunSettings(_reportRunContext, _replaceStandardPlaceholders); if (_reportRunContext.parmPrintDestination() == DocPrintDestination::Email) { DocERFormatGeneratorCBD erFormatGenerator = DocERFormatGeneratorCBD::constructWithDsp(str2Guid("{CB9B0D95-8BBF-4CB7-AE89-6FC47B62E204}"), this); // Run ER format generator. erFormatGenerator.run(); // Get the generated document as memory stream in original format (Excel). using (System.IO.MemoryStream documentContent = erFormatGenerator.getDocumentContentMemoryStream()) { // Check if the document was generated. if (documentContent != null) { // If so, add it as an additional email attachment to the outgoing email. container documentContentContainer = DocGlobalHelper::convertMemoryStreamToContainer(documentContent); _reportRunContext.emailPrintDestSettings().addAdditionalAttachment(strFmt("Customer account statement %1.xlsx", placeholder_custAccount), documentContentContainer); } } } return placeholderManager; } } |
The result of the code above are the outgoing emails with the attached two documents:
- PDF document generated by Docentric (or SSRS),
- Excel document generated by Electronic Reporting.
If you want to get the PDF output from the generated Excel document, you can! Just use the getPdfDocumentContentMemoryStream() method on the generator class instead.
1 2 3 4 5 6 7 8 9 |
// Convert the ER Format generated in Excel to PDF and get it as a memory stream. using (System.IO.MemoryStream documentContent = erFormatGenerator.getPdfDocumentContentMemoryStream()) { if (documentContent != null) { container documentContentContainer = DocGlobalHelper::convertMemoryStreamToContainer(documentContent); _reportRunContext.emailPrintDestSettings().addAdditionalAttachment(strFmt("CAS %1.pdf", placeholder_custAccount), documentContentContainer); } } |
This method invokes Microsoft Office Conversion Service, which is used for converting Configurable business documents in Word and Excel to PDF.
If you need to generate any Electronic reporting document to memory, check out our previous article!
Generate Electronic Reporting Format as Byte Array >>