# Pdf file into database like postgres

**URL:** <https://discourse.nodered.org/t/pdf-file-into-database-like-postgres/94308>\
**Category:** Developing Nodes\
**Tags:** function-node\
**Created:** [2 January 2025 03:45 UTC](https://discourse.nodered.org/t/pdf-file-into-database-like-postgres/94308 "2025-01-02T03:45:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hemanthv1](https://avatars.discourse-cdn.com/v4/letter/h/d07c76/32.png) [@hemanthv1](https://discourse.nodered.org/u/hemanthv1)\
**Post date:** [2 January 2025 03:45 UTC](https://discourse.nodered.org/t/pdf-file-into-database-like-postgres/94308/1 "2025-01-02T03:45:16Z")

</div>

Hi,  
I am trying to convert pdf files into base64 and log them in database. When using read file - "file-in" node and set output to output to base64 and include debug output. Base64 output is generated for the pdf file in debug console. however when we use the output and try to create pdf file using "[Base64 to PDF | Base64 Decode | Base64 Converter | Base64](https://base64.guru/converter/decode/pdf)" - pdf file is not generated.  
when use the website to convert to base64 and use the output to generated pdf file it is working.  
any suggestions.  
thanks

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [2 January 2025 06:24 UTC](https://discourse.nodered.org/t/pdf-file-into-database-like-postgres/94308/2 "2025-01-02T06:24:33Z")

</div>

> [@hemanthv1](#):
>
> When using read file - "file-in" node and set output to output to base64

This assumes that the input is a string, however, PDF is a binary format. Encoding is a translation/representation, not an actual conversion.

Set the file-in node to a 'single buffer object' and run it through a function node with something like:

```auto
const base64 = msg.payload.toString("base64")
msg.payload = base64
return msg

```

The output will be readable as pdf in base64.

To convert it back to a buffer:

```auto
const base64_string_input = msg.payload
msg.payload = Buffer.from(base64_string_input, 'base64')
return msg

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [3 March 2025 06:25 UTC](https://discourse.nodered.org/t/pdf-file-into-database-like-postgres/94308/3 "2025-03-03T06:25:26Z")

</div>

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