Output binary data from node

Describe the problem/error/question

How do I output the response from this http request within a code node as binary data.

Please share your workflow

Share the output returned by the last node

Information on your n8n setup

  • n8n version: latest
  • Database (default: SQLite): default
  • n8n EXECUTIONS_PROCESS setting (default: own, main): default
  • Running n8n via (Docker, npm, n8n cloud, desktop app): docker
  • Operating system: Ubuntu

Hey @atwork1,

There are few nodes what can make (image) or convert (Convert to File) binary files or you could use APIs like renderform.io or APITemplate
if you need PDF, I think that’s no easy, but maybe you can make image and convert it somehow? Or use pdf template api, check this
Also maybe you could find some community node, but I don’t know any what address this problem
If you need like JSON file to be binary I’ve made wf what download data from mongo as JSONL file (I need that for fine tuning)

check also those topics:

Thank you for your reply.
I’ve tried to encode the response to base64 and construct the binary file like you did, but the file i get isn’t a valid pdf file.

grafik

I’ve created a workflow using the gotenberg demo api and a sample pdf file that is loaded from https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf with a http request, so you see the results I’m getting.

I don’t know why the http-request node is dispayed as unknown in the preview … maybe a new version.? (Edit: yes its ther version, changing the node version to 4.1 will fix the preview, here in the thread)

PS: I need to use a code node, because I’m merging a variable number of PDF documents and the HTTP request node can’t handle that.
Edit: fixed some stuff

Yes, that makes sense. I was creating a JSONL file—which isn’t technically text, but it’s relatively straightforward compared to PDFs.

Just a quick question: how many PDFs do you need per month, and can you send this data to a third-party API? If so, I’d recommend using something like APITemplate.

Alternatively, I’ve set up a workflow that converts HTML to PDFs using Gotenberg, a tool specifically for PDF operations. You’ll need to install it, but it’s straightforward using the following Docker command:

docker run --rm -p 3333:3000 gotenberg/gotenberg:8

(Note: I changed the port to 3333 because 3000 was already in use on my system.)

References:

Hope this help;)
Simon

thanks,
I have a similar one for generating a HTML file filled with images and printing it with gotenberg.
Borderless, assuming all images have the same dimensions.

But it’s feels wrong and probaly breaks at the slightest variations of inputs…

Edit: posting the workflow it gives a 403 error for some reason. maybe because of the html
Edit2: posting without the html node

Hey,

So 403 means there is auth error, you use their instance or your local one? :thinking:

here in the Forum^^

when I add the html node I can’t post the reply.

The html is probably messing with the POST and being interpreted as actual html ā€˜code’.

Aaaaa sorry about that… I’m not sure why this is happening. Could you possibly share a link to a gist or something similar? Is everything working for you, or does your workflow still need some attention from us? :sweat_smile:

@bartv can you assist with 403 issue?

I’m still not able to get a valid pdf file.

how does the https node handle binary files? Can I use that ā€œprincipleā€ in the code node?

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.