Pages

Monday, January 14, 2008

Print PDF files from AX to specific printer

This job illustrates how you can print an external PDF file to a printer choosen in AX:

static void pdfprint(Args _args)
{
PrintJobSettings printJobSettings = new PrintJobSettings();
Dialog dialog = new Dialog();
DialogField dialogFileName;
str adobeExe;
str adobeParm;
;
dialogFilename = dialog.addField(typeid(FilenameOpen));

if (dialog.run())
{
printJobSettings.printerSettings('SysPrintForm');
adobeExe = WinAPI::findExecutable(dialogFileName.value());

adobeParm = strFmt(' /t "%1" "%2" "%3" "%4"',
dialogFileName.value(),
printJobSettings.printerPrinterName(),
printJobSettings.printerDriverName(),
printJobSettings.printerPortName());

winAPI::shellExecute(adobeExe, adobeParm);
}
}