How to Use the New Memory Print Destination
If you only want to generate a report as a container, byte array or memory stream, in order to send it to a web service or to implement some other custom scenarios, you don’t have to use the File print destination. You can use the new Docentric print destination called Memory that enables printing report to a container (byte array or memory stream) using either the original built-in SSRS report design or one of the related Docentric designs (aka templates).
Print Customer Invoice to Memory
In the following example we are going to generate Customer Invoice using its default Docentric design (aka template) and save it to a memory stream or container using the Docentric Memory print destination.
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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
public static void printSalesInvoiceToMemory() { SalesInvoiceController salesInvoiceController; SalesInvoiceContract salesInvoiceContract; Args args = new Args(); CustInvoiceJour custInvoiceJour; SalesInvoiceJournalPrint salesInvoiceJournalPrint; select custInvoiceJour where custInvoiceJour.SalesId != ''; // Add record to be printed. // In order to have the context table we need to set args.record(). args.record(custInvoiceJour); salesInvoiceController = SalesInvoiceController::construct(); salesInvoiceController.parmReportName( PrintMgmtDocType::construct(PrintMgmtDocumentType::SalesOrderInvoice).getDefaultReportFormat()); salesInvoiceContract = salesInvoiceController.parmReportContract().parmRdpContract(); salesInvoiceContract.parmCountryRegionISOCode(SysCountryRegionCode::countryInfo()); salesInvoiceController.parmArgs(args); salesInvoiceController.parmExecutionMode(SysOperationExecutionMode::Synchronous); SRSPrintDestinationSettings pds = salesInvoiceController.parmReportContract().parmPrintSettings(); pds.printMediumType(SRSPrintMediumType::Memory_DC); // Use the default Docentric design. pds.parmMemoryPrintDestSettings_DC().parmOutputFileFormat(DocOutputFileFormat::PDF); pds.parmMemoryPrintDestSettings_DC().parmUseSsrsBuiltInDesign(false); pds.parmSrsPrintReportSettings_DC().setProperty_PrintSrsOriginalDesign(false); /* Uncomment this code if you want to use the original SSRS design instead */ //pds.parmMemoryPrintDestSettings_DC().parmOutputFileFormatSrs(SRSReportFileFormat::PDF); //pds.parmMemoryPrintDestSettings_DC().parmUseSsrsBuiltInDesign(true); //pds.parmSrsPrintReportSettings_DC().setProperty_PrintSrsOriginalDesign(true); // Initalize SalesInvoiceJournalPrint class instance because there is no other way // NOT to use Print Management. salesInvoiceJournalPrint = SalesInvoiceJournalPrint::construct(); salesInvoiceJournalPrint.parmPrintFormletter(NoYes::Yes); salesInvoiceJournalPrint.parmUsePrintManagement(false); salesInvoiceJournalPrint.parmUseUserDefinedDestinations(true); salesInvoiceJournalPrint.parmPrinterSettingsFormLetter(salesInvoiceController.parmReportContract().parmPrintSettings().pack()); args.caller(salesInvoiceJournalPrint); args.parmEnumType(enumNum(PrintCopyOriginal)); args.parmEnum(PrintCopyOriginal::OriginalPrint); /* Collect the result of the execution */ // Register event handler to the RenderingComplete event. salesInvoiceController.renderingCompleted += eventhandler(DocExamplesPrintSalesInvoice::printSalesInvoiceToMemory_renderingComplete); // Start the report execution. salesInvoiceController.parmShowDialog(false); salesInvoiceController.startOperation(); } public static void printSalesInvoiceToMemory_renderingComplete(SrsReportRunController _sender, SrsRenderingCompletedEventArgs _eventArgs) { // Get the report execution info. DocReportExecutionInfo reportExecutionInfo = _eventArgs.parmReportExecutionInfo().parmReportExecutionInfo_DC(); DocPrintReportToMemoryExecutionInfo printDestMemoryExecutionInfo = reportExecutionInfo.parmPrintToMemoryExecutionInfo(); // Use the report content, e.g. upload it to Azure Blob storage. using (System.IO.MemoryStream reportMemoryStream = printDestMemoryExecutionInfo.getReportContentAsMemoryStream()) { DocAzureBlobHelper::uploadBlob('docentric-report-output', 'TestInvoice.pdf', reportMemoryStream); } // Do something else with the report content, e.g. send it to a web service... } |
Use the DocSrsReportGenerator class
The DocSrsReportGenerator class is introduced in 3.3.8 Docentric version and utilizes the Docentric Memory print destination. Learn how to use DocSrsReportGenerator >>
See also
How to Run a Docentric SSRS Report from Code >>
How to Use Custom Placeholders in Print Destinations >>
How to Change Print Destination Settings Dynamically >>