Skip to content

Base64 to PDF & File Converter · PDF to Base64

Convert Base64 to PDF online: paste raw Base64, a data URI or a whole JSON response. Detects the real file type, flags truncated PDFs, and does PDF to Base64.

No Tracking Runs in Browser Free
Decoding and encoding run entirely in your browser. Your Base64 and files are never uploaded.

Read as:

What file is this Base64? Check how it starts

Every file type begins with fixed "magic" bytes, so its Base64 begins with fixed characters. The prefixes below are computed from real file headers by the same engine this tool uses.

Base64 starts with File type Magic bytes (hex)
JVBERi0 PDF 25 50 44 46 2D
iVBORw0KGgoAAAANSUhEU PNG 89 50 4E 47 0D 0A 1A 0A 00 00 00 0D 49 48 44 52
/9j/ JPEG FF D8 FF
R0lGOD GIF 47 49 46 38
UEsDB ZIP / DOCX / XLSX / PPTX 50 4B 03 04
0M8R4KGxGu Office 97–2003 (DOC/XLS/PPT) D0 CF 11 E0 A1 B1 1A E1
H4sI Gzip 1F 8B 08
UklGR RIFF (WebP / WAV / AVI) 52 49 46 46
SUQz MP3 (ID3) 49 44 33
e1xydG RTF 7B 5C 72 74 66
Behaviour checked against RFC 4648, RFC 2045 and RFC 2397, and against the PDF, PNG, ZIP and Office file signatures. — Go Tools Engineering · Sep 30, 2026

Written and reviewed by the engineers who build Go Tools' encoding tools. Every length, prefix and example on this page is produced by the page's own engine and checked by automated tests.

Base64 to PDF — quick answers

What file is Base64 that starts with JVBERi0?

JVBERi0 = PDF A PDF. Every PDF begins with the bytes `%PDF-`, and those encode to `JVBERi0` in Base64. `iVBORw0KGgo` is a PNG, `/9j/` is a JPEG and `UEsDB` is a ZIP, which includes DOCX and XLSX.

How much bigger is Base64 than the original file?

+33.3% 4 characters for every 3 bytes, so about 33.3% larger: a 1 MB (1,048,576-byte) PDF becomes 1,398,104 characters. With a line break every 76 characters, as email attachments use, it is 1,434,896 characters, or 36.8% larger.

What is a Base64 PDF?

Base64 writes arbitrary bytes using only 64 safe text characters (A–Z, a–z, 0–9, +, /), with = as padding. Every 3 bytes become 4 characters. That lets a binary file such as a PDF travel through channels that only carry text — a JSON field, an XML element, an email body, a database text column. Converting Base64 to PDF simply reverses it: turn the characters back into bytes and save them with a .pdf extension. The trouble is that real Base64 rarely arrives clean: it comes with a data: prefix, JSON escapes, line breaks or a different alphabet, and many converters silently produce a file that will not open.

%PDF-1.4          → bytes 25 50 44 46 2D 31 2E 34
JVBERi0xLjQ=      → the same bytes in Base64
data:application/pdf;base64,JVBERi0xLjQ=   → data URI form

Features

Paste it as you got it

Handles data URIs, \/ and \n JSON escapes, quotes, MIME line breaks, URL-safe - _, %2B %2F from URLs, PEM headers and missing = padding — and shows each step it took.

Takes the whole JSON response

Paste {"code":0,"data":{"file":"JVBERi0…"}} as is. The longest Base64-looking field is used and its path (data.file) is shown, so you know which field was decoded.

Real type from magic bytes

PDF, PNG, JPEG, GIF, WebP, DOCX, XLSX, PPTX, ZIP, GZIP, MP3, MP4 and more than 40 other formats are recognised from their first bytes. The download gets the right extension even when the prefix says otherwise.

Explains files that will not open

Flags a PDF with no %%EOF (cut off while copying or by a column length limit), Base64 that was encoded twice, hex pasted as Base64, gzip-compressed data and encrypted PDFs.

Inline preview

PDFs open in the browser's built-in viewer, images and SVG are displayed, text and JSON are shown as text. HTML is never rendered — only its source — because it would run on this page.

PDF or any file to Base64

Drop a file up to 50 MB and get plain Base64 or a data URI, optionally URL-safe or wrapped at 76 characters, with the exact size overhead.

Base64 to PDF in Python, Java, JavaScript and more

Python

base64.b64decode

open('out.pdf', 'wb').write(base64.b64decode(s)). Use urlsafe_b64decode for - and _; b64decode ignores line breaks unless you pass validate=True.

Java

java.util.Base64

Files.write(Path.of("out.pdf"), Base64.getMimeDecoder().decode(s)). getDecoder() rejects line breaks; getUrlDecoder() is for - and _.

Node.js

Buffer

fs.writeFileSync('out.pdf', Buffer.from(s, 'base64')). Buffer accepts both alphabets and ignores whitespace, but it also silently skips any other illegal character instead of throwing, so check the result starts with %PDF-.

Browser JavaScript

atob / Uint8Array.fromBase64

Build a Uint8Array before making the Blob. Uint8Array.fromBase64() is the newer built-in; check support in your target browsers.

PHP

base64_decode

file_put_contents('out.pdf', base64_decode($s, true)). Pass true for strict mode, otherwise invalid characters are silently dropped.

C#

Convert.FromBase64String

File.WriteAllBytes("out.pdf", Convert.FromBase64String(s)). Whitespace is allowed; - and _ are not.

Command line

base64 -d / certutil

macOS and Linux: base64 -d < in.txt > out.pdf. Windows: certutil -decode in.txt out.pdf.

Base64 to PDF examples

Plain Base64 of a PDF

JVBERi0xLjQKMSAwIG9iago8PCAvVHlwZSAvQ2F0YWxvZyAvUGFnZXMgMiAwIFIgPj4K…
PDF · version 1.4 · downloaded as file.pdf

Starts with JVBERi0, which is %PDF-. Nothing to clean, so it is decoded as is.

String copied from a JSON response

"data:application\/pdf;base64,JVBERi0xLjQK…"
Read as: removed the surrounding quotes → undid JSON escapes → removed the data URI prefix (application/pdf)

PHP's json_encode and some Java serializers write / as \/. Pasted into a decoder that does not undo it, the backslash is an illegal character.

Whole API response

{"code":0,"data":{"name":"invoice.pdf","file":"JVBERi0xLjQK…"}}
Read as: took the field data.file out of the JSON

No need to cut the string out by hand. The longest Base64-looking field is used and its path is shown.

Labelled PDF, actually a PNG

data:application/pdf;base64,iVBORw0KGgoAAAANSUhEUgAA…
Warning: the data URI says application/pdf, but the bytes are PNG. Saved as file.png

Many converters would write a .pdf that no reader can open. The magic bytes win over the label.

Hex pasted instead of Base64

255044462d312e370a…
Warning: this looks like hexadecimal — read as hex it is a PDF. [Decode as hex]

Hex digits are all legal Base64 characters, so Base64 decoding does not fail; it silently produces garbage. 25 50 44 46 is %PDF.

How to convert Base64 to PDF

  1. 1

    Paste the Base64 as you got it

    Raw Base64, data:application/pdf;base64,…, a string copied out of JSON with \/ escapes, or the whole API response. For very long strings use Open a .txt file instead of pasting.

  2. 2

    Check how it was read

    The line under the box lists every clean-up step — prefix removed, escapes undone, padding added, field taken from the JSON. If something is wrong, the error names the exact character and position.

  3. 3

    Look at the detected type and warnings

    The badge shows the type read from the file's magic bytes. A yellow note appears if it is not actually a PDF, if the data URI lies about its type, or if the PDF is cut off before %%EOF.

  4. 4

    Preview and download

    PDFs open in the browser's own viewer, images and text are shown inline. Rename the file if you like and click Download. For the reverse direction, switch to PDF / file → Base64 and drop a file.

Why a Base64 PDF will not open: common mistakes

Decoding the data URI prefix along with the data

data:application/pdf;base64, is not part of the Base64. Leaving it in either throws (: and ; are illegal) or, in lenient decoders, corrupts the first bytes so the file no longer starts with %PDF-.

✗ Wrong
base64.b64decode(value)  # value = 'data:application/pdf;base64,JVBERi0…'
✓ Correct
b64 = value.split(',', 1)[1] if value.startswith('data:') else value
pdf = base64.b64decode(b64)

Writing the decoded bytes as text

A PDF is binary. Converting the decoded bytes to a string and writing that string with a text encoding replaces invalid bytes and changes line endings, which breaks the cross-reference table.

✗ Wrong
fs.writeFileSync('out.pdf', Buffer.from(b64, 'base64').toString())
✓ Correct
fs.writeFileSync('out.pdf', Buffer.from(b64, 'base64'))

Strict decoder given line-wrapped Base64

Java's Base64.getDecoder() rejects line breaks. Base64 from email or from base64 on Linux is wrapped at 76 characters. Use the MIME decoder, or remove whitespace first.

✗ Wrong
byte[] pdf = Base64.getDecoder().decode(wrapped);  // IllegalArgumentException
✓ Correct
byte[] pdf = Base64.getMimeDecoder().decode(wrapped);

URL-safe Base64 given to a standard decoder

JWTs and many URL parameters use - and _ instead of + and /, and drop the = padding. A standard decoder rejects them or decodes the wrong bytes.

✗ Wrong
base64.b64decode(token_part)  # contains - and _
✓ Correct
base64.urlsafe_b64decode(token_part + '=' * (-len(token_part) % 4))

Using atob() on its result as text

In the browser atob returns a binary string, one character per byte. Passing it to new Blob([str]) encodes it as UTF-8, turning every byte above 127 into two bytes. Copy it into a Uint8Array first.

✗ Wrong
new Blob([atob(b64)], { type: 'application/pdf' })
✓ Correct
const bytes = Uint8Array.from(atob(b64), c => c.charCodeAt(0));
new Blob([bytes], { type: 'application/pdf' })

Truncated string

A PDF ends with %%EOF. If the Base64 was cut by a VARCHAR column, a log line limit or an incomplete copy, the file decodes but readers show an error or missing pages. Compare the length with what the sender produced.

✗ Wrong
SELECT LENGTH(pdf_b64) FROM docs;  -- 65535: suspiciously round
✓ Correct
ALTER TABLE docs MODIFY pdf_b64 LONGTEXT;  -- or store the bytes in a BLOB

When you need Base64 to PDF

An API returns the PDF as Base64
Invoicing, e-signature and label-printing APIs often return documents inside JSON. Paste the response to check the document before writing the code that saves it.
Debugging a PDF that will not open
When the saved file is blank or corrupt, paste the same Base64 here. The tool tells you whether it is truncated, double-encoded, not a PDF at all, or fine — which means the bug is in how your code writes the file.
Sending a file in a JSON request
Many upload endpoints expect {"filename": …, "content": "<base64>"}. Encode the file here to build a test request for Postman or cURL.
Embedding a file in HTML, CSS or email
Produce a data URI for an inline PDF link, a font or a small image, or 76-column Base64 for a MIME email part.
Reading attachments from logs and databases
Files stored in a text column or printed to a log can be pulled straight back out — and a missing %%EOF tells you the column or the log line was too short.

How Base64 file encoding works

Why Base64 is 33% bigger
Each character carries 6 bits, so 3 bytes (24 bits) need 4 characters. The length is 4 × ⌈n ÷ 3⌉ with padding: 100 KB (102,400 bytes) becomes 136,536 characters. MIME wrapping adds CRLF after every 76 characters, so 1 MB becomes 1,434,896 instead of 1,398,104.
Standard and URL-safe alphabets
RFC 4648 defines two alphabets that differ only in the last two characters: + / (standard, section 4) and - _ (URL- and filename-safe, section 5). URL-safe Base64 usually omits = padding. Mixing both in one string means it was edited or joined.
Padding and impossible lengths
Padding = makes the length a multiple of 4. Without it, a remainder of 2 or 3 can be restored; a remainder of 1 is impossible for any valid Base64 — a character was lost or added. = in the middle usually means two strings were concatenated.
Magic bytes decide the type
A file declares its format in its first bytes: %PDF- for PDF, 89 50 4E 47 for PNG, 50 4B 03 04 for ZIP-based formats such as DOCX and XLSX. Those bytes fix the first Base64 characters, so the type can be read before decoding — see the table in the tool.
How a truncated PDF is detected
A PDF ends with %%EOF. If it does not appear in the last 1,024 bytes, the file was almost certainly cut short. The header may start up to 1,024 bytes in; most readers still open such files, so it is reported but not rejected.

Best practices for sending files as Base64

Send the MIME type and the file name with the data
Base64 carries no name or type. Put both next to it ({"filename": "invoice.pdf", "mime": "application/pdf", "content": "…"}) or use a data URI, so the receiver does not have to guess.
Check the magic bytes on the receiving side
Before saving, verify that the decoded bytes start with %PDF-. It catches wrong fields, double encoding and error pages returned as Base64 in one line of code.
Prefer multipart or a URL for large files
Base64 adds a third to the size and the whole string has to sit in memory. Above a few megabytes, multipart/form-data or a pre-signed download URL is lighter for both ends.
Store bytes, not Base64, in the database
A BLOB/bytea column is a third smaller and cannot be silently truncated like a VARCHAR. Encode to Base64 only at the API boundary.

Base64 to PDF — FAQ

How do I convert Base64 to PDF?
Paste the Base64 into the box on this page. It is decoded immediately, the PDF opens in the preview, and Download saves it as a .pdf. The prefix data:application/pdf;base64,, quotes, line breaks and JSON escapes can stay in — they are removed automatically.
Why won't my decoded PDF open?
The usual causes are: the data: prefix was decoded as part of the data; the bytes were written as text instead of binary; the string was cut off (no %%EOF at the end); the Base64 was encoded twice; or it is not a PDF at all — for example a PNG or a JSON error message. Paste the same string here: each of these cases shows a specific warning.
Is my file uploaded to a server?
No. Decoding, type detection, preview and encoding all run in your browser with JavaScript. Nothing you paste or drop is sent anywhere, so it is safe for invoices, contracts and ID documents.
How do I know what type of file the Base64 is?
Look at how it starts: JVBERi0 is PDF, iVBORw0KGgo is PNG, /9j/ is JPEG, R0lGOD is GIF, UEsDB is ZIP (and therefore DOCX, XLSX, PPTX), H4sI is gzip. The tool reads the decoded magic bytes and shows the type, and saves the file with the matching extension.
Can I convert Base64 to Word, Excel, an image or a ZIP?
Yes. Any file type can be decoded; the extension comes from the content. DOCX, XLSX and PPTX are recognised inside the ZIP container, and older DOC/XLS files are recognised as Office 97–2003. Images, audio and video are previewed; other types download directly.
How do I convert a PDF to Base64?
Open the PDF / file → Base64 tab and drop the PDF. Choose plain Base64 or a data URI, optionally URL-safe or wrapped at 76 characters, then copy it or download it as a .txt file.
What is the difference between Base64 and a data URI?
A data URI is Base64 with a header that states the type: data:application/pdf;base64,JVBERi0…. Browsers can open it directly as a link or src. APIs usually want only the Base64 part after the comma.
Why does it say "This is not a PDF"?
Because the decoded bytes do not start with %PDF-. The type shown is what the bytes actually are. Common surprises are a PNG or JPEG scan, a DOCX, a ZIP of several PDFs, or a JSON or HTML error message that was Base64-encoded in place of the document.
What does "no %%EOF at the end" mean?
Every PDF ends with the marker %%EOF. When it is missing, the Base64 was almost certainly truncated: copied only in part, cut by a database column such as a MySQL TEXT (65,535 bytes), or shortened by a log line limit. Get the full string again; decoding cannot recover missing data.
What does "decoded a second time" mean?
The decoded data was itself Base64 text. That happens when a value is encoded once by your code and again by a framework or HTTP client. The tool decodes the inner layer only when it turns out to be a recognisable file, so ordinary text is never unwrapped by mistake.
Is there a size limit?
Pasted text can be up to 100 MB and files up to 50 MB for encoding. For very long Base64, Open a .txt file is faster than pasting. Previews of text show the first 100,000 characters; the download is always complete.
Why is the PDF preview blank on my phone?
Mobile browsers handle embedded PDFs differently; some show only the first page or nothing. Use Open in a new tab or Download — the file itself is not affected.

Related Tools

View all tools →