← All Posts
Use S1SEVEN’s certificate tools to convert a JSON certificate to a PDF

Use S1SEVEN’s certificate tools to convert a JSON certificate to a PDF

Eamon O'CallaghanEamon O'CallaghanNovember 23, 2022

Simplifying the process with Node-Red

S1SEVEN provides several open-source tools for use with digital certificates. They can be found at https://github.com/s1seven/schema-tools.

They are generally intended for developer use, but they can easily be integrated into a Node-Red flow to simplify the process. If you haven’t already set up Node-Red, follow the instructions here.

Installing generate pdf

To make the process as easy as possible, we have provided a custom node that can be installed directly from Node-Red. This custom node integrates our schema tools with Node-Red, meaning you don’t have to set them up manually.

With Node-Red, installing modules is easy. Click on the top-right menu button and select Manage palette from the drop-down menu.


We need to install the following node: @s1seven/node-red-generate-pdf. Just click on the Install tab, type in the name of the node, and click the install button.


Using generate pdf

Installing @s1seven/node-red-generate-pdf will add a new node called generate pdf to the S1Seven section on the left sidebar.


Drag it into the main workspace to get started, as seen in the following screenshot.


generate pdf expects to receive a JSON certificate as input, so we can take an inject node and wire it up to generate pdf.


Double-click on the inject node and change msg.payload to a JSON object.


Setting msg.payload to JSON

Copy and paste a JSON certificate’s contents into the input box beside msg.payload and click Done.


Paste the JSON certificate

Then, get a green debug node and attach it to the end of the flow. Your flow should look something like the one below:


After clicking the Deploy button, hit the inject button, and after a second or so, you should see the output in the debug tab to the right (if you don’t see the debug tab, click the icon that looks like a bug, as seen in the screenshot above). The output will be a buffer which you will see printed as numbers:


Now, all we need to do is take that buffer and convert it into a file. We can do that easily by attaching it to a write file node, which you will find under the storage category in the left sidebar.


Double-click on the write file node, and specify the Filename. For this demonstration, I’m using test.pdf.


By default, this will create a PDF called test.pdf in the node-red working directory. If you prefer to save it in another location, you can specify an absolute path and filename in Filename.

For example, if I want to save it to downloads on a Mac, I can set Filename to /Users/<user>/Downloads/test.pdf. On Windows, this would be c:\Users\<user>\Downloads.


Now when I hit the Deploy button and inject the JSON certificate, a PDF called test.pdf is saved to my Downloads folder.

Expanding the flow

Now that the hard part is done, you can expand this flow and make it more useful. For example, you could add an upload button to the UI, allowing you to upload JSON files instead of copy-pasting them.

You could also set up an MQTT node to listen for events from S1SEVEN, such as receiving a certificate, then automatically pass that certificate to generate-pdf-node and save it as a PDF.