PowerApps is a marvellous product, but printing support is quite weak. I am currently in the process of developing a PowerApp and printing support to on-premise printers is a must. YouTube video that demos the functionality:
PrintNode works really well with Microsoft Power Automate and Power Apps. After only a few minutes of setup, I was able to print PDF files directly from PowerApps to my on-premise printers. In my case the PDF files were stored in a SharePoint list.
The printing is performed with a HTTP interaction between Power Automate and PrintNode, so these instructions would work equally well from any flow, but my use case was PowerApps.
The high level steps are as follows:
- Register on PrintNode and setup the client.
- Select which Printers you want to print to and gather their unique ids.
- Create a flow which uses the HTTP Connector to send print jobs to Printnode.
Setup PrintNode Client
After you have registered on printnode.com, install the client on a machine that has local access to the printers you want to print. Then take a note of the printers that you want to print to. Mine look like this:
From the screenshot above, you can see I have two printers enabled with the unique IDs of 69363024 and 68663025.
Setup Printer Definitions in a SharePoint list
A simple SharePoint list with four fields works well to drive a printer selection drop down in PowerApps. My list looks like this:
And the resulting drop down looks like this:
Or you could set up the printer definitions directly in your PowerApp by using the Table Function. This code would produce the same result as the SharePoint list:
Table( {printNodeID:"69363025", Description:"HP Laserjet M506", Location: "Pauls Office", Image: "http://tachytelic.net/wp-content/uploads/HP-LaserJet-Enterprise-M506-Printer.jpg" }, {printNodeID:"69363024", Description:"HP PageWide Pro 477DW", Location: "Merrians Office", Image: "http://tachytelic.net/wp-content/uploads/HP-PageWide-Pro-477dn-web.jpg" } )
Create a flow to receive print request from PowerApps and submit to PrintNode
The flow is simple to create. Here is a high level image of my flow:
Define the required variables for the Flow from PowerApps
The flow starts with the creation of the three variables that are needed to complete the flow. The three variables are
- printNodeID
- pdfPath
- documentName
This step isn’t strictly required, you can simply use “Ask in PowerApps” to fill the required values further down the flow. I prefer to do it this way as it makes the flow easier to comprehend when you are calling it from PowerApps. Each variable is initialized like this:
Retrieve the PDF that you want to print
In my case, the document I want to print is already in PDF format, if your’s is not, then you will need to add some steps to your flow to get it into PDF format.
I am using the flow action “Get file content using path” to get the PDF file from a SharePoint list.
Compose your JSON and submit to PrintNode
The PrintNode API is extensive and I have only scratched the surface. The code I am using simply submits a PDF for printing to a particular printer. I am using the “Compose” action to create the required JSON.
{ "printerId": "@{variables('printNodeID')}", "title": "@{variables('documentName')}", "contentType": "pdf_base64", "content": "@{base64(body('Get_file_content_using_path'))}", "source": "PowerApps" }
Note that the PDF file needs to be Base64 encoded, otherwise the submission to PrintNode will fail.
The final step is to use the HTTP action to submit the job to PrintNode:
This step is simple. You need the URI, which is: https://api.printnode.com/printjobs
The Authorization header. I used a concat expression for the value of:
concat('Basic ', base64('apiKeyFromPrintNode:'))
and the body of the HTTP request is the output of the compose step.
Connect your new PrintNode flow to your PowerApp
The final step is to connect your PowerApp to your newly created PrintNode flow. I have connected mine to a button control which initiates the flow with the following code:
printViaPrintNode.Run(dropDownSelectPrinter.Selected.printerID, pdfURL, pdfName)
Obviously I named the flow “printViaPrintNode” and the values being passed in are associated to the variables assigned in the flow.
This is the Print screen withing my PowerApp. PDF Preview on the right hand side with the printer options on the left and an image of the printer that is going to process the job.
It’s also interesting to note that PrintNode do have a “Raw” printing option which can be used to drive Label printers, but I can think of some other uses for that option to, which I am going to play with.
So overall, although PowerApps does not have great native printing support, PrintNode goes a long way to solving the problem!
Arthur Vanderhaeghen says
Hi Paulie,
Love your work. Is it possible as well to pass on the amount of copies and the printer tray/drawer you want the printer to use?
Sunil Prakash says
I wanted to print the document library files every 4 hours from power automate workflow directly to the printer eliminating the Power app, Is that possible?
Paulie says
It is possible
Philip Miller says
Hello Paulie,
Thanks for your post. I’ve been troublehooting implementation of this solution but keep getting an error message:
{
“code”: “BadRequest”,
“message”: “Incorrect request body: (request body).content must be present”,
“uid”: “8bb15c17-7112-4951-97f1-f448511fb1bc”
}
I copy my base64 converted text from the failed flow into https://base64.guru/converter/decode/file and it looks ok. Do you have any suggestions for this?
Cheers
Phil.
Paulie says
Hey Phil,
Sorry, it’s been a while since I looked at this. It does seem to be suggesting there is something missing from your request – have you tried manually forming a request just to test?
Philip Miller says
Hello Paulie, Thanks for the prompt reply. I’ve since reached out to Print Node supprt, but as yet without response. Would you be able to point me to something that describes how to manually form the request to test the issue please? You made this solution appear ‘out of the box’. I’m a bit frustated given that I cannot make it work. Cheers Phil.
Paulie says
Please use the get in touch form and I will take a look with you