Base64 to PDF Converter
LocalDecode a Base64 PDF string back into a downloadable PDF file
Drag & drop files here or click to browse
Base64 • Max 100 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 turn a Base64 string back into a PDF file?
Supply the Base64 content and decode it to get a normal .pdf download. Both raw Base64 and a full data:application/pdf;base64 URL are accepted, whitespace and line breaks are stripped automatically, and the decoded bytes are checked for the PDF file signature so you find out immediately whether the payload was really a PDF. Decoding happens locally.
About the Base64 to PDF Converter
Convert raw Base64 or a data:application/pdf;base64 URL back into a PDF file. The decoder removes whitespace and checks for the PDF file signature, but it does not fully parse or repair the decoded document.
- Decode a Base64 PDF value copied from an API response or database field.
- Turn a Base64 PDF data URL into a normal .pdf file for download.
- Check whether decoded bytes begin with the PDF file signature without uploading them to a server.
How to use the Base64 to PDF tool
- 1
Upload Base64 file
Select Base64 file from your device or drag file into the upload area.
- 2
Review files
Review the selected files and continue when they are ready.
- 3
Convert to PDF
Run the Base64 to PDF tool to create the PDF output.
- 4
Download the result
Download the finished file. The original file stays on your device and is not uploaded.
Why does a decoded Base64 PDF sometimes refuse to open?
Usually because the string was damaged before it reached the decoder, not because decoding failed. The classic causes are a truncated value copied out of a log or a database cell with a length limit, a data URL prefix left in place where raw Base64 was expected, URL-safe Base64 using dashes and underscores instead of plus and slash, or double encoding. This tool checks that the decoded bytes start with the PDF file signature, which tells you quickly which side of the problem you are on.
What does the signature check actually verify?
That the decoded bytes begin with the marker every PDF starts with. That is a fast, reliable way to catch the common failures — wrong field, wrong encoding, truncated string — but it is not a full parse. The tool does not validate the document’s internal structure and does not attempt to repair it, so a payload that was corrupted in the middle can pass the check and still open badly. If that happens, the fault is in the stored value, not the decode.
Where do these Base64 PDF strings come from?
Almost always from a system that had to move a document through a text-only channel: a JSON API response, an XML or SOAP envelope, a webhook body, a database text column, an email template, or a log line captured during debugging. Decoding it locally is the quickest way to answer the question that actually matters — is the document in there intact, or did the integration break before it ever got stored?
Are my files uploaded when decoding Base64 into a PDF?
No. The string is decoded by your browser and the resulting file is handed straight to the downloader, so a payload lifted out of production logs or a customer’s API response is never re-uploaded somewhere else while you inspect it. That is worth caring about precisely because debugging is when people are least careful about where they paste things.
Decode a Base64 string back to a PDF in code
Three things break decoding more often than anything else: a data URI prefix that was never stripped, whitespace or newlines left in the string, and URL-safe Base64 (- and _ instead of + and /). Each snippet below handles all three.
JavaScript (browser)
atob plus a Blob gives you a downloadable file with no server round-trip.
function base64ToPdfBlob(input) {
let payload = input.trim()
if (payload.startsWith("data:")) payload = payload.slice(payload.indexOf(",") + 1)
payload = payload.replace(/\s+/g, "").replace(/-/g, "+").replace(/_/g, "/")
const binary = atob(payload)
const bytes = new Uint8Array(binary.length)
for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i)
// A real PDF always starts with the five bytes %PDF-
if (binary.slice(0, 5) !== "%PDF-") throw new Error("Not a PDF")
return new Blob([bytes], { type: "application/pdf" })
}Node.js
Buffer.from with the base64 encoding, then a signature check before writing.
import { writeFile } from "node:fs/promises"
const payload = input.replace(/^data:[^,]+,/, "").replace(/\s+/g, "")
const bytes = Buffer.from(payload, "base64")
if (bytes.subarray(0, 5).toString("latin1") !== "%PDF-") {
throw new Error("Decoded bytes are not a PDF")
}
await writeFile("invoice.pdf", bytes)Python
b64decode with validate=False so stray newlines are ignored rather than fatal.
import base64, re
payload = re.sub(r"^data:[^,]+,", "", raw.strip())
data = base64.b64decode(payload)
assert data[:5] == b"%PDF-", "Decoded bytes are not a PDF"
with open("invoice.pdf", "wb") as handle:
handle.write(data)Shell
Strip the prefix with sed, then pipe through base64 -d.
sed -e "s|^data:[^,]*,||" invoice.b64 | base64 -d > invoice.pdf
# Confirm the first bytes really are a PDF header
head -c 5 invoice.pdfPHP
base64_decode with strict mode so a corrupt string fails loudly.
<?php
$payload = preg_replace("/^data:[^,]+,/", "", trim($raw));
$bytes = base64_decode($payload, true);
if ($bytes === false || substr($bytes, 0, 5) !== "%PDF-") {
throw new RuntimeException("Not a valid Base64 PDF");
}
file_put_contents("invoice.pdf", $bytes);C#
Convert.FromBase64String throws on whitespace-free invalid input, so clean it first.
string payload = Regex.Replace(raw.Trim(), "^data:[^,]+,", "");
byte[] bytes = Convert.FromBase64String(payload);
if (Encoding.ASCII.GetString(bytes, 0, 5) != "%PDF-")
throw new InvalidDataException("Decoded bytes are not a PDF");
File.WriteAllBytes("invoice.pdf", bytes);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
Decoding is the same tools in reverse. The one thing to watch is that a data URI prefix has to be removed before the decoder sees it.
base64
Built in on macOS and Linux
base64 -d invoice.b64 > invoice.pdfOn macOS the flag is -D on older releases; -d works on current versions and on GNU coreutils.
sed + base64
Built in
sed -e "s|^data:[^,]*,||" invoice.b64 | base64 -d > invoice.pdfStrips a data:application/pdf;base64, prefix first, which is the single most common cause of a decode failure.
PowerShell
Built in on Windows
[IO.File]::WriteAllBytes("invoice.pdf", [Convert]::FromBase64String((Get-Content invoice.b64 -Raw)))FromBase64String rejects whitespace, so use -Raw and trim the string if the file has trailing newlines.
Frequently Asked Questions
Need More Tools?
Explore our collection of 58 free PDF tools, all with privacy-first processing.
Browse All Tools