AXForum  
Вернуться   AXForum > Microsoft Dynamics AX > DAX Blogs
All
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск Все разделы прочитаны

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 20.11.2018, 14:11   #1  
Blog bot is offline
Blog bot
Участник
 
25,475 / 846 (79) +++++++
Регистрация: 28.10.2006
ievgensaxblog: MSDyn365FO. How-to send PDF document to a printer from X++
Источник: https://ievgensaxblog.wordpress.com/...rinter-from-x/
==============



In AX 2012 it could be done with 2 lines of X++ code:

#WinAPIWinApi::shellExecute(fileName,'', fileFolder, #ShellExePrint);Now it’s not that easy. Files are in Azure BLOB storage instead of a folder, printers are in a local network that is not accessible from the cloud and WinApi is deprecated. To print standard reports Document Routing Agent should be installed. We need it to send PDF directly from the system as well.

Let’s say we want to print PDF file saved in document attachments (DocuRef). First, we need to check if a printer selected by a user is active and get printer details:

SrsReportPrinterContract activePrinterContract = SrsReportRunUtil::getActivePrinter(printerName);if (!activePrinterContract.parmPrinterName()){ return;}printerName value should come from somewhere, for example a field on a form. In this case we can use SrsReportRunUtil::lookupPrinters() method to add a lookup with all available printers:

public static void lookupPrinters(FormStringControl _ctrl){ SrsReportRunUtil::lookupPrinters(_ctrl);}Then we need to create print destination settings:

SRSPrintDestinationSettings srsPrintDestinationSettings = new SRSPrintDestinationSettings();srsPrintDestinationSettings.printMediumType(SRSPrintMediumType::Printer);srsPrintDestinationSettings.fileFormat(SRSReportFileFormat::PDF);srsPrintDestinationSettings.printerName(activePrinterContract.parmPrinterName());srsPrintDestinationSettings.printerWhere(activePrinterContract.parmPrinterPath());srsPrintDestinationSettings.printerWhere() is important bit here. This parameter accepts path to a printer. It’s possible to install multiple DRA on different servers and path for DRA installed on a print server could be different to path for DRA installed on any other server, so watch for this.

To send document we need to read file into a memory stream:

container fileCon = DocumentManagement::getAttachmentAsContainer(_docuRef);var stream = Binary::constructFromContainer(fileCon).getMemoryStream();And create new DocumentContract:

DocumentContract documentContract = DocumentContractFactory::Instance.Create(DocumentContractType::Pdf);documentContract.Name = _docuRef.Name;documentContract.Contents = stream.ToArray();documentContract.TargetType = TargetType::Printer;documentContract.Settings = srsPrintDestinationSettings.printerPageSettings();documentContract.ActivityID = emptyGuid();If you send multiple documents ActivityID should be initialized for each document, because DRA ignores documents with same ActivityID  and DocumentContractFactory::Instance.Create does not actually create new instance, so you want either reset ActivityID or manually populate it.  Don’t forget to add a reference to Microsoft.Dynamics.AX.Framework.DocumentContract:

using Microsoft.Dynamics.AX.Framework.DocumentContract;And finally send the contract to DRA:

SrsReportRunPrinter::sendDocumentContractToDocumentRouter(documentContract);Whole method:

public static void sendToPrinter(DocuRef _docuRef, str _printerName){ SrsReportPrinterContract activePrinterContract = SrsReportRunUtil::getActivePrinter(_printerName); if (!activePrinterContract.parmPrinterName()) { return; } SRSPrintDestinationSettings srsPrintDestinationSettings = new SRSPrintDestinationSettings(); srsPrintDestinationSettings.printMediumType(SRSPrintMediumType::Printer); srsPrintDestinationSettings.fileFormat(SRSReportFileFormat::PDF); srsPrintDestinationSettings.printerName(activePrinterContract.parmPrinterName()); srsPrintDestinationSettings.printerWhere(activePrinterContract.parmPrinterPath()); container fileCon = DocumentManagement::getAttachmentAsContainer(_docuRef); if (fileCon) { var stream = Binary::constructFromContainer(fileCon).getMemoryStream(); if (stream) { DocumentContract documentContract = DocumentContractFactory::Instance.Create(DocumentContractType::Pdf); documentContract.Name = _docuRef.Name; documentContract.Contents = stream.ToArray(); documentContract.TargetType = TargetType::Printer; documentContract.Settings = srsPrintDestinationSettings.printerPageSettings(); documentContract.ActivityID = emptyGuid(); SrsReportRunPrinter::sendDocumentContractToDocumentRouter(documentContract); } }}If you want to check documents printed or see if there are any in a queue you can go to Common -> Inquiries -> Document routing status









Источник: https://ievgensaxblog.wordpress.com/...rinter-from-x/
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
ievgensaxblog: MSDyn365FO. Collation conflict during data upgrade from AX 2012 Blog bot DAX Blogs 0 30.08.2018 20:12
goshoom: How to send emails from code in AX 7 Blog bot DAX Blogs 0 01.06.2016 01:26
atinkerersnotebook: Walkthrough & Tutorial Summary Blog bot DAX Blogs 1 09.09.2013 09:11
atinkerersnotebook: Using Service Management to Track Service Orders Blog bot DAX Blogs 1 25.08.2013 19:16
furnemont: How-to series: Send SMS messages from CRM 2011 (part 3) Blog bot Dynamics CRM: Blogs 0 13.06.2011 12:11
Опции темы Поиск в этой теме
Поиск в этой теме:

Расширенный поиск
Опции просмотра

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 04:54.
Powered by vBulletin® v3.8.5. Перевод: zCarot
Контактная информация, Реклама.