There are same extensions to generate PDF documents based on flow data, like PDF Factory or PDF Builder. I’m looking for an operation to generate a file based on given json data…
I try to generate a PDF with these extensions but I get errors like “TypeError: Cannot create property ‘images’ on string“…
Does anyone have experience generating PDF documents in Directus within a flow?
Does anyone have a solution to fix the extension errors?
I use TextToAnything for this and it works really well. I have a flow script that generates some html from my data and sends that to the Text2Anything plugin which outputs a PDF that I can attach as a file.
There’s a small monthly fee for it but it’s very cheap really.
Hi Burvs, thanx for your hint! Text2Anything is a commercial product. I have to register, and there are some terms and conditions. That's not what I'm looking for. I'd like to use an open-source product...
Im the owner of TextToAnything.
TextToAnything is an extension that allows you to generate PDFs (from HTML) easily.
Let me know if you have any questions or add me on Discord.
Hi @Attacler, thank you very much for your support! I am looking for a simple way to generate a formatted PDF from JSON. I have looked at TTA. It is a powerful tool that offers much more than I need. I will definitely keep an eye on it.
Burvs’ TextToAnything setup (a Run Script that builds the HTML from your data, then the extension turns it into a PDF you can attach as a file) is the closest ready-made answer, and Attacler, who makes it, has offered to help above.
On the “Cannot create property ‘images’ on string” error: JavaScript throws that when code tries to set a property on a string, so the PDF extension most likely got a JSON string where it expected an object. If your data comes in as text, for example from a webhook trigger or a Request URL step, add a Run Script step before the PDF operation that returns a parsed object:
Then point the PDF operation at that step’s result instead of the raw text.
If you’d rather not install an extension, a Flow can do it with core operations:
Run Script: build an HTML string from the trigger data (a template literal with your fields and some CSS for the layout).
Request URL: POST that HTML to an HTML to PDF service. Gotenberg is the usual self-hosted, open source renderer, but its routes take multipart form uploads, so it’s easier to call from a small custom operation than from Request URL, which sends a JSON or text body.
Request URL again: POST the finished file’s link to your own /files/import endpoint ({"url": "...", "data": {...}}) with a static token, so the PDF lands in the file library and you can relate it to the item.
For step 2, thirds.ai has an HTML to PDF endpoint that takes a JSON body ({"html": "..."}), so it fits Request URL without any multipart handling. A render is a job: the response is 200 if it has already finished and 202 while it is still running, and then you poll GET /v1/pdf/{id} or take a webhook. Each download link lasts 15 minutes, so import it straight away. In a Flow, a Sleep step followed by a second Request URL for the job, or a second Flow with a webhook trigger, covers the 202 case. The page linked above shows the request and the job response.
Hi Burvs, thanx for your hint! Text2Anything is a commercial product. I have to register, and there are some terms and conditions. That's not what I'm looking for. I'd like to use an open-source product...
– EdgarFurkertThen check this one out https://github.com/karamokoisrael/directus-extension-flow2pdf
– Abdallah