Looking for a way to convert HTML (which I build inside another workflow) into a PDF, preferably inside my own network. So I found Gotenberg, which looks very promising.
Their API expects a file named index.html: HTML API call and I don’t yet understand how to do that in n8n: should I write my HTML into a file like that? And call the API with a path to that file (but where would that path point to)?
Gotenberg looks nice. I tested it out and it works well.
They have a docker which you can run locally. You need to call their API to get a PDF from a URL you pass
Then for n8n, I would assume you need to write the html to a local file and present it on a localip:port/document.html or pass it as a binary to the gotenberg endpoint.
Sure, I have their docker image running here already. The missing bit for me is how to get the HTML output of my other node(s) into the Webhook-Call or the HTTP-Request. I might ask the Gotenberg-people also.
If it is possible to “store” the generated HTML in some kind of temporary file usable by the workflow, this would be a possibility, right?
Thank you, yes, I already had something similar. So far not yet successful, but I am a newbie so that has to be expected
“JSON to binary” requires JSON as input, sure, so I have to add a node to convert HTML to JSON first. That’s my next step.
(In the end I will have to write a HTML document containing data from multiple JSON objects, adding some css-formatting, and this should be converted into a PDF, then pushed into some API again. At least that’s my current plan)
Yes, I am able to write a test HTML file to “plaintext.html”.
Changing the field “File Name” in the “Write Binary File” node to “/tmp/index.html” doesn’t change the File Name on the output side.
The Gotenberg Webhook Module wants “index.html” according to: Webhook | Gotenberg
I have a HTTP request node already calling the Gotenberg container which is able to call a Webhook in n8n … (and receive the pdf file) so I get closer.
The HTTP Request calls the Gotenberg-container with several parameters:
according to Webhook | Gotenberg I send headers for Webhook-URLs (that’s where the generated pdf should be delivered to) and most important: the path to the html-file that should be converted.
Is that a header at all?
The curl-example says (I skip the Webhook-headers here):
After reading the docs, the files=@/path/to/file seems to indicate it needs a file on its local disk.
It cannot be passed in using the form-data from my testing.
You will need to write the file on the docker storage of the Gotenberg docker (or better yet, a shared folder between the host, n8n,gotenberg), then pass that relative path to the above node.
I have limited knowledge of share storage on docker so cant help.
I am sure it will work.
At the very least adding a local xyz.html to the gotenberg docker and calling the sample node I pasted above should work.
If that works, shared storage will work too
You will obviously have to change the url parameter to files and then see how that @ sign works for syntax
Yes. Do you have a recommendation how to host that “temporary” file? I didn’t yet manage to make the mentioned container work, but I was busy with other things. It would be great to have a Node in n8n to do that, right?