For years, the Zebra team has posted sample code and best practices for printing. Individually they are simple and easy to use, but they do not always fully detail what is required for enterprise application development.
This new blog series will detail several techniques for dealing with more advanced printing problems. First, we’ll review how to keep your application responsive even with long running printing needs. The next blog will review batch or large scale printing techniques. Please feel free to leave comments for future topics.
In terms of software, printing takes a long time. Because you are working with a peripheral device, the speed and type of communication also plays a huge factor. The sample code that Zebra has shared shows printing of individual labels or receipts on separate threads due to these limitations. When a user initiates a print job, they may not want to wait for it to print before sending the next job. In this case, most of the sample code available will not work well.
There are a limited number of connections you can have open to a printer at once. If you open multiple threads and try to print from each of them, you may have issues as you run out of connections or try to merge multiple print jobs on one connection. If this occurs, you’ll need to look at a different architecture for handling print jobs.
One suggestion is to add a queuing server to parcel out print jobs to a printer manager activity which is controlling the connection. The attached reference architecture illustrates this scenario. This is especially useful for direct user interaction initiated printing. The UI remains responsive and takes the input adding more print jobs any time the need arises and as quickly as a user adds them. The architecture also shows how to handle poor connectivity. If you primarily use wired connections, many of the checks are unnecessary.
The architecture does not show as well what is needed for large scale or batch printing where hundreds or thousands of prints need to be initiated. A future blog will dig deep into this scenario.
There may be other methods to handle this scenario and we welcome your feedback on it. This architecture has worked for several large Zebra customers and .NET sample code will be added soon.
ResponsivePrinting.pdf 141.6 K