How to convert a PDF to Base64
- Drop the PDF on the box or choose it with the file picker. Several PDFs at once are fine.
- Pick the format under Output as. This page starts on Plain Base64, which is what most APIs want.
- Tick Wrap at 76 only if the string goes into a raw MIME email. Leave it off for JSON and HTML.
- Press Copy output. For large documents use Save as .txt, which writes
yourfile.pdf.b64.txt.
The info line shows the file name, size and MIME type, and the counters below show the encoded size and overhead. The PDF is read by your browser and is not uploaded; the page’s Content Security Policy allows no network requests except Cloudflare’s page-view count.
Where a Base64 PDF is used
JSON cannot carry raw bytes, so services that accept documents inside the request body take them as Base64. E-signature platforms, invoicing and accounting systems, OCR and document-parsing services, and AI models that read PDFs all use this pattern. The field names differ from API to API, but the shape is usually a file name, a MIME type and a Base64 string.
AI models that read PDFs directly usually take the file the same way: Base64 data plus the media type application/pdf, either as separate fields or as one data URI. They tend to limit file size and page count, so split long documents before encoding.
Attachments in MIME email are Base64 with lines of at most 76 characters. If you are assembling a message by hand or testing an SMTP library, Wrap at 76 gives you exactly the body of a part like this:
Content-Type: application/pdf; name="invoice.pdf"
Content-Disposition: attachment; filename="invoice.pdf"
Content-Transfer-Encoding: base64
JVBERi0xLjcKJeLjz9MK...
Mail-sending APIs that take JSON want the attachment unwrapped in a field instead. More in Base64 in email, and the EML decoder pulls attachments out of a raw message.
To encode several PDFs, drop a batch and press Copy all as JSON to get an array with one {name, type, size, data} object per document, useful for seeding a test database or a bulk import.
For download links, the HTML <a download> output produces a link that saves the PDF when clicked:
<a href="data:application/pdf;base64,JVBERi0xLjcK..." download="invoice.pdf">invoice.pdf</a>
That is handy for single-file HTML reports. Linking to the data URI without download usually fails: Chrome blocks page-initiated navigation to data: URLs in the top-level window, so the click opens nothing or a blank tab. Firefox makes an exception for PDFs, which is why a link can work in one browser and not another.
A small PDF stored as a Base64 constant lets a unit test exercise an upload or parsing path without a fixture file next to it.
What the Base64 of a PDF starts with
Every PDF begins with %PDF- and a version number, followed by a line break. In Base64 that header is easy to spot:
| File header | Base64 |
|---|---|
%PDF-1.4 + newline | JVBERi0xLjQK |
%PDF-1.5 + newline | JVBERi0xLjUK |
%PDF-1.7 + newline | JVBERi0xLjcK |
%PDF-2.0 + newline | JVBERi0yLjAK |
If your output does not start with JVBERi0, the file you picked is not a PDF, or it has junk in front of the header. A string starting PCFET0NUWVBF (<!DOCTYPE) or PGh0bWw (<html) is HTML, which often means a download link saved an error page with a .pdf name.
How large the encoded PDF gets
Base64 output is 4 characters for every 3 bytes, and wrapping adds one newline per 76 characters:
| PDF size | Base64 length | With Wrap at 76 |
|---|---|---|
| 100 KB | 136,536 chars | 138,332 chars |
| 1 MB | 1,398,104 chars | 1,416,500 chars |
| 5 MB | 6,990,508 chars | 7,082,488 chars |
| 10 MB | 13,981,016 chars | 14,164,976 chars |
| 25 MB | 34,952,536 chars | 35,412,437 chars |
Sizes are in binary units (1 MB = 1,048,576 bytes). Check the API’s request size limit against the encoded size, not the file size. If the API also accepts a multipart upload or a pre-signed URL, that route skips the overhead and suits documents of tens of megabytes better. The size calculator does this arithmetic for any size.
This tool encodes large PDFs in your browser, but it does not copy output above roughly 48 MB to the clipboard. Use Save as .txt in that case.
Encode a PDF in code
Python, building a JSON body:
import base64, json
from pathlib import Path
path = Path("invoice.pdf")
data = base64.b64encode(path.read_bytes()).decode("ascii")
body = json.dumps({"filename": path.name, "content": data})
Node.js:
import { readFile } from "node:fs/promises";
const b64 = (await readFile("invoice.pdf")).toString("base64");
const payload = JSON.stringify({ filename: "invoice.pdf", content: b64 });
From a shell with GNU coreutils and jq (-w 0 disables line wrapping):
base64 -w 0 invoice.pdf > invoice.b64
jq -n --rawfile content invoice.b64 '{filename: "invoice.pdf", content: $content}'
The filename and content keys are placeholders; use the names your API documents. More options are on Base64 in Python and Base64 in Node.js.
Common problems
- The API says the Base64 is invalid. Most often the
data:application/pdf;base64,prefix is included where the API wants bare Base64, or line breaks frombase64without-w 0,openssl base64(wraps at 64) or Wrap at 76 are left in. Some APIs also reject URL-safe Base64. - The decoded PDF is corrupt or empty. The string was cut somewhere, often by a log line limit, a database column that is too short or a spreadsheet cell. Compare the length with the table above. A PDF’s last bytes are
%%EOF, so a complete encoding decodes to something ending in that marker. - The PDF opens on your machine but the receiver sees a blank page. Base64 does not change the document, so the PDF itself is the issue: missing fonts, an unusual PDF version or a damaged cross-reference table. Test by decoding the string with Base64 to PDF and opening the result.
- Base64 is not encryption. Anyone who has the string can decode the document. If the PDF is confidential, protect the channel or encrypt it; see encoding vs encryption.
FAQ
How do I send a PDF in a JSON request?
Encode the file as plain Base64 and put the string in the field your API documents for file content, usually next to a file name and a MIME type of application/pdf. The JSON output gives you a ready object with name, type, size and data to adapt.
Can I convert a password-protected PDF to Base64?
Yes. Base64 encodes the bytes as they are, encryption included. The encoded file is still protected, and whoever decodes it still needs the password to open it.
How do I recognize a Base64-encoded PDF?
It starts with JVBERi0, the encoding of %PDF-. The next characters show the version, for example JVBERi0xLjc for PDF 1.7.
Why does my Base64 PDF link open a blank tab?
Chrome blocks pages from navigating the top-level window to a data: URL, and other browsers restrict it too. Use the HTML <a download> output, which saves the file instead of opening it, or build a Blob URL in JavaScript.
How big will my PDF be in Base64?
About 4/3 of the file size: a 3 MB PDF becomes roughly 4 MB of text. The overhead counter under the output shows the exact value, and Base64 to PDF reverses it.