Over the past year, Microsoft has been working hard to bring its new Cloud printing service, Universal Print, to general availability.
As a part of Universal Print, developers get access to a set of Graph APIs that allows analysis and modification of print job payload data. This feature enables a few different scenarios, including adding security (e.g. redactions or watermarks) to a Universal Print-based workflow.
As a curious engineer, I wanted to see how different it would be for an independent software vendor (ISV) to use our Mako™ Core SDK to modify a print job flowing through Universal Print, instead of using a more traditional route of using a virtual printer driver.
Thinking about the workflow a little more, I came up with the following design:
In the design above, we can see the end-user’s Word document gets printed to a virtual printer. This allows the ISV to be notified of the job, and modify it accordingly using Mako. Once modified, the ISV then redirects the job on to the physical printer for printing.
There’s a couple of nice things about this design:
Firstly, it uses the Graph API to access Universal Print, which is an easy-to-use and well documented REST API. Secondly, since the functionality is accessed via a REST API, it allows our ISV service to be written in whichever Mako supported language we like.
I chose C# to make best use of the C# Graph API SDK.
Developing the service
There are five main steps to developing the service:
- Handle print job notifications
- Download the print job payload
- Modify the payload
- Upload the payload
- Redirect to the target printer
Handle print job notifications
To be notified of print jobs in Universal print, you can use the Graph’s change notifications. These will allow you to sign up to a notification, which will call a provided webhook.
Download the print job payload
Once we have notification that a print job has been sent to our virtual printer, we can start downloading its payload.
Here we use the appropriate Graph APIs, along with standard Graph authentication to access the print job’s document. We then simply save it to disk.
Modify the payload
Once we have the document on disk (although Mako can also modify streams too!), we can open the document and modify it using Mako’s document object model (DOM).
Alternatively, Mako can also convert from one page description language (PDL) to another. This is useful in situations where your destination printer doesn’t support the input PDL.
Upload the payload
Uploading the modified document is straightforward. This time we use the Graph API to create an upload session, and use the WebClient class to put the document back into the original print job.
Redirect to the target printer
And finally, after the print job has been updated, we can redirect it onto another printer. This redirection also automatically completes the print job and task.
Alternatively, if we want to be a little more green, we could always send the document to OneDrive, Sharepoint, or another document management system. After doing so, you then complete the print job and its associated task.
See it in action
We actually coded this demo live in our last Mako webinar, showing an implementation where an ISV wants to automatically redact content.
Access the code directly at our GitHub repository or watch the webinar recording below:
Try it out
We’re keen to talk to you about your Universal Print project and see how we can help. Contact us here.
For more information about Mako, visit globalgraphics.com/mako.
About the author
Further reading:
- Carry out complex tasks for your print workflow easily with Mako
- Improving PDF accessibility with Structure Tagging