← 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
Share

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.

637e1af077e97c10a06dda28_1*E5t4y9Qn1LN4Czkxuv3rzg.png

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.

637e1af03720a3718deea798_1*p_pOf2foYJdPSJG0onXl-A.png

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.

637e1af08f6e3bae1c39c688_1*4dN-fWqSpoA4YjuOkap86Q.png

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

637e1af0db842eef31dad04c_1*EAIwA9HRXdCR3Dyx1UYmLQ.png

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

637e1af0cdf4dba3cf1c85c0_1*K1QcS5-9-EDDw6ggsqe6SA.png

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

637e1af09f3c79478f1fc228_1*ogj9YHtl0bEYDSjGEMSJEA.png

Setting msg.payload to JSON

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

637e1af08f6e3b806339c689_1*H55UZsgFN4fSgI7D7GmjnQ.png

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:

637e1af0cd90337df812e163_1*WwCwVDpZC4ljs2IZsWx-LA.png

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:

637e1af0dd2efe2fb25014f5_1*xBjXwwe9Typzo-2z-oG7eg.png

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.

637e1af19824383b9e484c2a_1*h9lbt1uqu33FzbFxYXPuPQ.png

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

637e1af00c998d71987ed735_1*eU2E-dAtLb_DmaiX8vsmUA.png

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.

637e1af12850db7a02892705_1*bKpth8Yp-TuLxxdxL7okiA.png

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.