PDF to Base64 Converter
LocalEncode a PDF file as a Base64 string for APIs, JSON, and embedding
Drag & drop files here or click to browse
PDF • Max 50 MB
Files are processed in your browser and never uploaded
Privacy First
Your files are processed entirely in your browser. Nothing is uploaded to any server.
How do I convert a PDF to a Base64 string?
Select the PDF, choose the output shape you actually need — raw Base64, a data URI, a JSON envelope, XML, an HTML embed, object, iframe or download link, or a CSS url() value — and encode. You get back a file already in that form, ready to paste straight into the destination. Encoding is done by your browser, so the PDF never reaches a server.
About the PDF to Base64 Converter
Convert PDF files to Base64-encoded strings directly in your browser and take the output in the shape the destination actually expects: raw Base64, a data URI, a JSON envelope, XML, a ready-to-paste HTML embed, object, iframe or download link, or a CSS url() value. Raw output can be wrapped at 76 or 64 characters per line for MIME and PEM-style transports.
- Convert a PDF to Base64 before sending it in a JSON API request, and take the output already wrapped in the JSON envelope so there is nothing left to hand-assemble.
- Produce a data:application/pdf;base64 URI for an embed, an email template or a test fixture, without pasting the prefix on yourself and getting the MIME type wrong.
- Get a working HTML embed, object, iframe or download link for the PDF, so the page renders it without any server route or object URL bookkeeping.
- Wrap raw output at 76 or 64 characters for a MIME transport, a PEM-style block, or a system that rejects lines longer than a few hundred bytes.
- Check before you send whether the encoded string will fit a request-body limit, since Base64 grows the payload by roughly a third.
How to use the PDF to Base64 tool
- 1
Upload PDF file
Select PDF file from your device or drag file into the upload area.
- 2
Choose settings
Choose settings such as Output format, Line wrapping before processing.
- 3
Convert to BASE64
Run the PDF to Base64 tool to create the BASE64 output.
- 4
Download the result
Download the finished file. The original file stays on your device and is not uploaded.
Why is the Base64 string bigger than the PDF?
Because Base64 spends four characters to represent every three bytes, so the encoded form is about a third larger than the original file — that is arithmetic, not overhead you can tune away. The exact encoded length is ceil(bytes / 3) × 4. Plan for it when the payload has to fit inside a request-size limit, a column width, or a message-queue cap. A 6 MB PDF becomes roughly 8 MB of text, which is enough to trip default body-size limits on plenty of API gateways.
Which output format should you pick?
Raw Base64 for a JSON field or database column where the receiving code adds its own prefix. Data URI when the string goes into an iframe or embed src, an anchor download attribute, or an API field documented as taking a data URI. The JSON and XML envelopes when you want the filename, MIME type and byte length travelling alongside the payload rather than assumed. The four HTML options and the CSS url() value are complete, working snippets for rendering the document in a page without any server route. Sending a prefix where none is expected is one of the most common causes of corrupt-file errors.
When should Base64 be wrapped at 76 or 64 characters?
Wrap at 76 when the string is going into a MIME body, because RFC 2045 defines that line length and some mail transports still fold or reject longer lines. Wrap at 64 for PEM-style blocks and for systems that inherited that convention from OpenSSL. Leave it unwrapped everywhere else. Wrapping is offered only for raw output on purpose: a newline inside a data URI, a JSON string, an HTML attribute or a CSS url() breaks the parser reading it, so choosing a wrapped width with any of those formats selected leaves the payload on one line and says so.
Should you Base64 a PDF for an API at all?
Sometimes it is the only option, and sometimes it is a habit worth questioning. It is genuinely the right answer when the transport is JSON-only, when you are embedding a document inside a signed payload, or when you need a self-contained test fixture. It is the wrong answer for large files, where multipart upload or a pre-signed URL avoids both the size inflation and the memory cost of holding the whole document as a string.
Are my files uploaded when encoding a PDF as Base64?
No, and this is the tool where the usual alternative is most alarming. Encoding a PDF normally means pasting a confidential document into the first web form that appears in search results, which hands the entire file to a stranger in one action. Here the bytes are read locally and encoded by the browser, so a signed agreement or a customer record becomes a Base64 string without ever being transmitted.
Encode a PDF as Base64 in code
The same conversion in six languages. All of them read the file as bytes and Base64-encode those bytes — the only thing that varies is which standard library call does it. Nothing here needs a package install.
JavaScript (browser)
FileReader gives you a data URI directly; slice off the prefix if you want raw Base64.
const file = document.querySelector("input[type=file]").files[0]
const dataUri = await new Promise((resolve, reject) => {
const reader = new FileReader()
reader.onload = () => resolve(reader.result)
reader.onerror = () => reject(reader.error)
reader.readAsDataURL(file)
})
// "data:application/pdf;base64,JVBERi0xLjcK..."
const base64 = dataUri.slice(dataUri.indexOf(",") + 1)JavaScript (fetch a URL)
When the PDF is already on a URL, go through an ArrayBuffer rather than a Blob round-trip.
const response = await fetch("/invoice.pdf")
const bytes = new Uint8Array(await response.arrayBuffer())
let binary = ""
for (let i = 0; i < bytes.length; i += 0x8000) {
binary += String.fromCharCode(...bytes.subarray(i, i + 0x8000))
}
const base64 = btoa(binary)Node.js
Buffer does the encoding; no dependency required.
import { readFile } from "node:fs/promises"
const bytes = await readFile("invoice.pdf")
const base64 = bytes.toString("base64")
const dataUri = "data:application/pdf;base64," + base64Python
b64encode returns bytes, so decode to ASCII before putting it in JSON.
import base64
with open("invoice.pdf", "rb") as handle:
base64_pdf = base64.b64encode(handle.read()).decode("ascii")
# 76-character MIME lines, if the transport wants them
with open("invoice.pdf", "rb") as handle:
wrapped = base64.encodebytes(handle.read()).decode("ascii")cURL
Encode on the shell and post the result as a JSON field.
# macOS
base64 -i invoice.pdf -o invoice.b64
# GNU coreutils (-w 0 stops it wrapping at 76 columns)
base64 -w 0 invoice.pdf > invoice.b64
curl -X POST https://api.example.com/documents \
-H "Content-Type: application/json" \
-d "{\"data\":\"$(cat invoice.b64)\"}"PHP
base64_encode over the raw file contents.
<?php
$base64 = base64_encode(file_get_contents("invoice.pdf"));
$dataUri = "data:application/pdf;base64," . $base64;C#
Convert.ToBase64String, with the option that inserts MIME line breaks.
byte[] bytes = File.ReadAllBytes("invoice.pdf");
string base64 = Convert.ToBase64String(bytes);
// 76-character lines separated by CRLF
string wrapped = Convert.ToBase64String(bytes, Base64FormattingOptions.InsertLineBreaks);How much bigger does Base64 make a PDF?
About a third bigger, always. Base64 turns every three bytes into four printable characters, so the encoded length is exactly ceil(bytes / 3) × 4, rounded up to a multiple of four with = padding. That is a 33.3% increase before any JSON escaping, and it is why a PDF that uploads fine as multipart form data is rejected when the same file is sent as an inline Base64 field.
| Example file | PDF size | Base64 length |
|---|---|---|
| One-page invoice | 45 KB | 60 KB |
| Ten-page contract | 250 KB | 333 KB |
| Scanned passport page | 1.2 MB | 1.6 MB |
| Illustrated 40-page report | 8 MB | 10.7 MB |
| Full scanned manual | 32 MB | 42.7 MB |
Which request-body limits does that break?
Work backwards from the ceiling: divide the limit by 1.37 to get the largest PDF that still fits once encoded and wrapped in a JSON object.
- Vercel serverless function request body (4.5 MB) — fits a PDF of roughly 3.4 MB or less.
- AWS Lambda synchronous invoke payload (6 MB) — fits a PDF of roughly 4.5 MB or less.
- Amazon API Gateway payload (10 MB) — fits a PDF of roughly 7.5 MB or less.
Above those sizes, stop sending Base64. Upload the PDF as multipart/form-data, or hand the client a pre-signed URL and send only the resulting object key in your JSON. Base64 in a request body is a convenience for small documents, not a transfer mechanism for large ones.
How to do this offline, on the command line
Every operating system already ships a Base64 encoder. If you are doing this more than once, do it on the command line.
base64 (macOS)
Built in
base64 -i invoice.pdf -o invoice.b64BSD base64 writes one unbroken line by default.
base64 (GNU coreutils)
Built in on Linux
base64 -w 0 invoice.pdf > invoice.b64Without -w 0 GNU base64 wraps at 76 columns, which is the MIME convention and breaks a data URI.
PowerShell
Built in on Windows
[Convert]::ToBase64String([IO.File]::ReadAllBytes("invoice.pdf")) > invoice.b64certutil -encode also works but adds BEGIN/END header lines you then have to strip.
Frequently Asked Questions
Need More Tools?
Explore our collection of 58 free PDF tools, all with privacy-first processing.
Browse All Tools