We need all the connected documents to be printed in one batch and we must not print the next X++ page before the attached documents are printed.
So we need to figure out if the shell and the printer are finished printing the attached documents before sending the next document from AX.
Luckily we can use the .NET library System.Printing to query the queue and in particular we can call the NumberOfJobs to figure out if the attached documents have been printed.
Here's a few bits of code for querying the printer queues:
System.Printing.PrintServer printServer
= new System.Printing.LocalPrintServer();
System.Printing.PrintQueueCollection printQueueCollection
= printServer.GetPrintQueues();
System.Printing.PrintQueue printQueue;
System.Collections.IEnumerator enumerator;
;
// Print the local server name
print printServer.get_Name();
// Enumerate and print names of all the queues on the server
enumerator = printQueueCollection.GetEnumerator();
while (enumerator.MoveNext())
{
printQueue = enumerator.get_Current();
print printQueue.get_FullName();
}
// Get information for a particular print queue
printQueue = new System.Printing.PrintQueue(printServer,
"HP Color LaserJet 5550 PS");
print printQueue.get_Description();
print printQueue.get_NumberOfJobs();
print ClrInterop::getAnyTypeForObject(printQueue.get_IsBusy());
print ClrInterop::getAnyTypeForObject(printQueue.get_IsPrinting());
pause;
In AX 2012 I would probably have placed the supporting code in a Visual Studio project rather than calling these CLR objects from X++.
*This post is locked for comments