PDFVela — pdfvela.com

How to send a PDF to an API as Base64

An e-invoice, e-signature or shipping API wants the document in a JSON field. Here is how to turn the PDF into the right kind of text, check it and avoid the errors that make the request fail.

By · Updated November 10, 2026

What the API usually expects

Most document APIs describe a JSON body with a field called content, file, data or document. Its value is the Base64 code of the PDF, often next to a file name and a type:

{
  "fileName": "invoice-1024.pdf",
  "mimeType": "application/pdf",
  "content": "JVBERi0xLjcKJ..."
}

Before writing any code, read the documentation for three things: the field name, whether a data: prefix is wanted (usually not) and the size limit.

1. Turn the PDF into Base64

The quickest way to get a test value is PDF to Base64. Choose the PDF, pick Base64 code only and copy the result. If you want a whole request body to start from, pick JSON instead — it adds the file name and type for you. The PDF is encoded in your browser and is not uploaded, which matters when the test document is a real invoice.

Check the result: it should start with JVBERi0, contain no spaces and, apart from one or two = signs at the end, only letters, digits, + and /.

2. Send it from your code

The same step in three common languages. Each one reads the file, encodes it and posts the JSON:

# curl (Linux / macOS): base64 -w 0 keeps it on one line
curl -X POST https://api.example.com/documents \
  -H "Content-Type: application/json" \
  -d "{\"fileName\":\"invoice.pdf\",\"content\":\"$(base64 -w 0 invoice.pdf)\"}"
// Node.js 18+
import { readFile } from 'node:fs/promises';
const content = (await readFile('invoice.pdf')).toString('base64');
await fetch('https://api.example.com/documents', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ fileName: 'invoice.pdf', content }),
});
# Python 3 with requests
import base64, requests
with open("invoice.pdf", "rb") as f:
    content = base64.b64encode(f.read()).decode("ascii")
requests.post("https://api.example.com/documents",
              json={"fileName": "invoice.pdf", "content": content})

On macOS the curl line uses base64 -i invoice.pdf instead of -w 0. The address and field names are examples; use the ones from your service's documentation.

3. Check the round trip

If the service returns the document or a stored copy as Base64, paste that answer into Base64 to PDF. Seeing the first page and the page count is the fastest proof that nothing was lost on the way. The detailed steps for that direction are in How to save a Base64 string as a PDF file.

Common mistakes

SymptomLikely causeFix
"Invalid Base64"Line breaks (76-character lines) or a data: prefixSend the bare code on one line
"Payload too large" (413)The PDF is too big after encodingShrink it with Compress PDF
The PDF opens blank or brokenThe string was cut offEncode again and send the whole value
Accented names look wrongFile name sent in the wrong encodingKeep the JSON body in UTF-8

Ready to try it? It is free and your file stays on your device.

Open PDF to Base64

Questions about sending a PDF as Base64

Why do APIs want Base64 instead of the file?

JSON can only carry text. Base64 writes the PDF's bytes with letters, digits, + and /, so the whole document fits in one string field next to the other data, such as the customer number or the invoice date.

Should I send the data:application/pdf;base64, prefix?

Usually not. Most APIs expect only the code, which starts with JVBERi0. Send the data URI only when the documentation shows it, or when a browser needs a URL, for example in an iframe.

The API says the Base64 is invalid. What is the most common cause?

Line breaks or a prefix in the string, or a code that was cut off when it was pasted. Use the bare code on a single line and check that the end of the string arrived complete.

How large can the PDF be?

That depends on the service, but the text is about a third larger than the file, so a 3 MB PDF becomes roughly 4 MB of JSON. Many APIs stop at a few megabytes; compressing the PDF first is the simplest fix.

Is Base64 a form of encryption?

No. Anyone who has the code can turn it back into the document. Send it only over HTTPS and never paste a confidential PDF into a website that uploads it.