Hi Shahil,
I've tried following your guide to print pdf attachments (docuref) records and for some reason I cannot get it to work. One thing to note that I am doing differently is setting up print management, but even with hardcoded values it does not appear to work.
Here is the code I'm using:
DocuRef docuRef = this.getDocuRef(); Microsoft.Dynamics.AX.Framework.DocumentContract.PdfDocumentContract pdfDocumentContract = Microsoft.Dynamics.AX.Framework.DocumentContract.DocumentContractFactory::Instance.Create( Microsoft.Dynamics.AX.Framework.DocumentContract.DocumentContractType::Pdf); container documentContainer = DocumentManagement::getAttachmentAsContainer(docuRef); System.IO.MemoryStream documentMemoryStream = Binary::constructFromContainer(documentContainer).getMemoryStream(); pdfDocumentContract.Name = docuValue.Name; pdfDocumentContract.Contents = documentMemoryStream.ToArray(); pdfDocumentContract.Settings = printDestination.printerPageSettings(); pdfDocumentContract.TargetType = Microsoft.Dynamics.AX.Framework.DocumentContract.TargetType::Printer; pdfDocumentContract.ActivityID = Microsoft.Dynamics.AX.Framework.Reporting.Shared.InstrumentationHelper::EnsureActivityIdIsSet(); SrsReportRunPrinter::sendDocumentContractToDocumentRouter(pdfDocumentContract);
It routes the document to the document router, but nothing actually comes out of the printer. When I test with and SSRS report, it works just fine (see the screenshot below). I've inspected the contents of the pdfDocumentContract and printDestination objects and they appear to be correctly constructed.
The screenshot shows the first line is an SSRS rendered to screen and then sent to the printer vs the bottom which is an attachment sent directly to the printer via code.
Does anybody have any ideas as to what I am doing wrong?