PDF to Base64 Converter

Drop a PDF and copy the Base64 string in the shape your code needs: raw text, a data URL, a JSON attachment, an HTML iframe, or a MIME email part. The file is read in your browser and never reaches Toolexe.

Encode a PDF to Base64

Your PDF
Drop a PDF here or pick one from your device. Files up to 40 MB. Nothing uploads.

The page checks the real bytes, not the file extension. A renamed Word file gets rejected. Page count comes from the PDF page tree, and files saved with compressed object streams hide the count, so the row says so instead of guessing.

Output format

Plain Base64 text with no prefix. REST APIs, database fields, and environment variables expect this one.

Raw Base64 only. URL-safe swaps + and / for - and _ and drops the = padding. The other tabs follow fixed rules.

JVBERi0xLjcKJeLjz9MKMSAwIG9iago8PCAvVHlwZSAvQ2F0YWxvZyAvUGFnZXMgMiAwIFIgPj4K

Your encoded PDF shows up here. Every valid PDF starts with JVBERi0.
Characters
0
Size change
+0%

Does the encoded string fit?

  • AWS Lambda payload, 6 MBsynchronous call Waiting
  • Amazon API Gateway, 10 MBREST request body Waiting
  • Gmail message, 25 MBattachments after encoding Waiting

Read a PDF data URL from left to right

Every Data URL from this converter has five parts. Knowing them lets you spot a broken string by eye, before a decoder throws a vague error at you.

The payload of a valid PDF always opens with JVBERi0. Those seven characters are the bytes %PDF- run through Base64, and the PDF format requires every file to start with them. A string opening with anything else came from a different file type, or picked up a stray quote mark or byte order mark at the front.

One exception: some older PDF writers put a few junk bytes before the header, and Adobe Reader tolerates up to 1,024 of them. The inspector above accepts the same window and flags the offset, since a strict decoder on the other end might not.

Pick the tab by where the string goes

The encoding is identical in every tab. What changes is the wrapper around the string, and the wrong wrapper is the most common reason an API rejects a perfectly good PDF.

DestinationTab and settingsWatch for
JSON body of a REST API callJSON attachment, or Raw Base64 with no breaksNo escaping needed. The Base64 alphabet has no quotes or backslashes. Strip the data: prefix if you copied a Data URL by mistake.
Raw email with an attachmentMIME partLines stay at 76 characters. Some mail servers reject longer lines, and RFC 5322 caps any line at 998.
Inline preview on a web pageHTML iframe or Data URLA data URL in a plain link opens a blank tab. Chrome, Firefox, and Edge block top-level navigation to data: URLs.
URL query string or pathRaw Base64, URL-safe onThe decoder needs the URL-safe alphabet from RFC 4648 section 5. A standard decoder chokes on - and _.
PEM-style config or legacy toolingRaw Base64, 64-character linesRemove the line breaks again before the same string goes into JSON.
Environment variable or secret storeRaw Base64, no breaksMost .env parsers stop reading at the first newline. Kubernetes Secrets want standard Base64 in the data field.

How much bigger the PDF gets

Base64 turns every 3 bytes into 4 characters. For a file of n bytes the encoded length is:

4 × ⌈n ÷ 3⌉

The result is a flat 33.3 percent increase, plus up to two = padding characters. Line breaks cost extra. MIME wrapping at 76 characters adds a CRLF pair per line, another 2.6 percent. The rows below show the largest PDF each common ceiling accepts.

PDF sizeBase64 lengthWhere the line falls
200 KB273,068 chars (266.7 KB)A one-page invoice or receipt. Fits anywhere, including a single database row.
1 MB1,398,104 chars (1.33 MB)Still comfortable for an API body. Pasting a string this long into some code editors starts to lag.
4.5 MB6,291,456 chars (6.00 MB)Exactly the AWS Lambda synchronous payload ceiling, before the JSON around the string.
7.5 MB10,485,760 chars (10.00 MB)Exactly the Amazon API Gateway REST payload ceiling.
18.75 MB26,214,400 chars (25.00 MB)The Gmail message ceiling, with zero room left for body text or headers.

The fit meter in the converter uses these figures against the length of the active tab. Treat a Tight fit as over the line. Request headers, JSON keys, and the email body all count toward the same cap.

When a PDF should stay a file

Base64 solves one problem: moving binary data through a channel built for text. Outside this one job, the extra third in size buys you nothing.

Saving PDFs in a database

A text column holds a third more data than a binary column for the same file, and every query selecting the row drags the whole document along. Put the PDF in object storage and keep the URL in the row.

Uploading from a web form

multipart/form-data sends the raw bytes. Encoding first wastes 33 percent of the upload, and the server has to decode before saving.

Hiding a document

Base64 is an encoding, not encryption. Anyone holding the string gets the PDF back with one command. Only a file the Password row marks as Encrypted stays locked after decoding.

Files above 40 MB

This page stops at 40 MB, since a 53 MB string slows copy and paste in most tabs. Use the terminal: base64 -w 0 report.pdf > report.b64 on Linux, base64 -i report.pdf -o report.b64 on macOS.

Turn the string back into a PDF

Test the round trip before wiring the string into production. Each snippet below writes the original bytes back to disk or opens them in a viewer. For a quick check without code, paste the string into the Base64 to PDF converter.

JavaScript, browser

const bytes = Uint8Array.from(atob(b64), c => c.charCodeAt(0));
const blob = new Blob([bytes], { type: 'application/pdf' });
window.open(URL.createObjectURL(blob));

Python

import base64

with open("invoice.pdf", "wb") as f:
    f.write(base64.b64decode(b64, validate=True))

PHP

$bytes = base64_decode($b64, true);
if ($bytes === false) {
    throw new RuntimeException('Not valid Base64');
}
file_put_contents('invoice.pdf', $bytes);

Linux or macOS shell

base64 --decode invoice.b64 > invoice.pdf
head -c 8 invoice.pdf   # prints %PDF-1.x

Strings made with the URL-safe option need - and _ turned back into + and / first. Python's base64.urlsafe_b64decode reads the URL-safe alphabet directly, though you still have to put the = padding back. Strict mode in PHP and validate=True in Python both reject a string with a data: prefix still attached.

PDF to Base64 questions

Short answers on privacy, size, prefixes, and protected files.

Why does my Base64 PDF string start with JVBERi0?

Every PDF begins with the bytes %PDF-, and those five bytes encode to JVBERi0 in Base64. Seeing JVBERi0 at the start is a fast sign the string holds a PDF. A string starting with iVBORw0 is a PNG, and UEsDB is a ZIP or a DOCX.

Is my PDF uploaded anywhere?

No. The browser reads the file through the File API and the JavaScript on this page encodes the bytes on your device. Toolexe never receives the PDF or the string. Closing the tab discards both.

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

Only for browser attributes such as an iframe src. APIs, databases, and the JSON tab expect raw Base64. Sending the prefix to an API is a common cause of invalid Base64 errors, since the colon and semicolon sit outside the Base64 alphabet.

What is the largest PDF this converter accepts?

40 MB. A bigger file produces a string over 53 MB, which slows copying and pasting in most browser tabs. Use base64 -w 0 on Linux or base64 -i on macOS for anything larger.

Does Base64 compress or change my PDF?

Neither. Decoding returns the exact bytes you started with. The string is about 33 percent larger than the file, so shrink the PDF with a compressor first if size is the problem.

Why does the Pages row say not readable?

PDF 1.5 and later allow the page tree to sit inside compressed object streams. Reading the count would mean decompressing those streams, which this page skips to stay fast. The PDF itself is fine, and the Base64 output is unaffected.

Will a password-protected PDF encode?

Yes. The encrypted bytes encode like any others, and the decoded file still asks for the password. The Password row shows Encrypted when the file carries an Encrypt entry in its trailer.