Base64 Files
API · JSON · cURL · No Upload

PDF to Base64 Converter

Convert any PDF to Base64 — and get a ready-to-use JSON payload, fetch snippet, or cURL command. Runs entirely in the browser; your PDF is never uploaded.

PDF to Base64

Drop PDF here or click to select

PDF files only · max 25 MB

Upload a PDF to see the Base64 output

When to use Base64 for PDFs:Base64 is best for small PDFs in JSON API payloads. For larger PDFs, binary upload or multipart/form-data is usually more efficient.

How to Convert a PDF to Base64

1

Upload a PDF file

Drag and drop a PDF onto the upload zone, or click to browse. The file is read entirely in your browser — no data is sent to any server.

2

Choose an output format

Pick raw Base64, Data URL, JSON payload, API fetch snippet, or cURL command depending on your use case.

3

Copy or download

Click Copy to send the result to the clipboard. For larger PDFs, use Download .txt to save the full output to a file.

Using PDF Base64 in APIs — Code Examples

Common ways to send a Base64-encoded PDF in real API calls.

Node.js fetchjs
const fs = require('fs')

const pdfBuffer = fs.readFileSync('document.pdf')
const base64 = pdfBuffer.toString('base64')

await fetch('https://api.example.com/upload', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    filename: 'document.pdf',
    mime: 'application/pdf',
    encoding: 'base64',
    data: base64,
  }),
})
Python requestspython
import base64, requests

with open('document.pdf', 'rb') as f:
    b64 = base64.b64encode(f.read()).decode()

requests.post('https://api.example.com/upload', json={
    'filename': 'document.pdf',
    'mime': 'application/pdf',
    'encoding': 'base64',
    'data': b64,
})
cURL with heredocbash
B64=$(base64 -i document.pdf)

curl -X POST https://api.example.com/upload \
  -H 'Content-Type: application/json' \
  -d @- <<EOF
{
  "filename": "document.pdf",
  "mime": "application/pdf",
  "encoding": "base64",
  "data": "$B64"
}
EOF
SendGrid email attachmentjs
const attachment = {
  content: base64String,   // your Base64 PDF
  filename: 'invoice.pdf',
  type: 'application/pdf',
  disposition: 'attachment',
}

await sgMail.send({
  to: '[email protected]',
  from: '[email protected]',
  subject: 'Your invoice',
  text: 'Please find your invoice attached.',
  attachments: [attachment],
})

When to Use Base64 for PDFs

Best suited for small PDFs that need to be transmitted via JSON or embedded directly in markup.

REST API File Upload

Send a PDF through a JSON-based API without needing multipart/form-data. Base64 lets you inline the file directly in the JSON body.

Email API Attachments

Services like SendGrid, Mailgun, and AWS SES accept Base64-encoded PDF attachments directly in their JSON payloads.

Embed PDF in HTML

Use the Data URL format to embed a PDF directly in an HTML object or iframe tag — no separate file hosting needed.

Store in a JSON Database

Embed small PDFs as Base64 string fields directly in MongoDB documents, Firebase Realtime Database, or DynamoDB.

Frequently Asked Questions

Should I use Base64 or binary upload for PDFs?

Use Base64 for small PDFs (under 1 MB) in JSON API payloads when multipart/form-data is not supported or adds complexity. For larger PDFs, binary upload via multipart/form-data or a direct PUT to a signed URL is more efficient and avoids the ~33% size overhead.

What is the Data URL format for a PDF?

A PDF Data URL uses the prefix data:application/pdf;base64, followed by the Base64 string. It can be used as the src or data attribute of an HTML object or embed element.

Can I embed a Base64 PDF in HTML?

Yes. Use an object element with data="data:application/pdf;base64,..." or an iframe with src="data:application/pdf;base64,...". Browser support varies — Chrome and Firefox work well; Safari has some limitations.

Does Base64 encoding change the PDF content?

No. Base64 is lossless — it converts binary PDF bytes to ASCII text and back without any modification. The decoded file is byte-for-byte identical to the original.

Why is the Base64 output larger than the original PDF?

Base64 encodes 3 bytes as 4 ASCII characters, adding about 33% overhead. A 1 MB PDF produces about 1.37 MB of Base64 text. This is inherent to Base64 encoding and cannot be avoided.

Is the PDF file uploaded to a server?

No. All encoding is done in the browser via the File API. Your PDF data never leaves your device — the tool works even when offline.