Skip to main content
PDFBase

Base64 to PDF Converter

Local

Decode a Base64 PDF string back into a downloadable PDF file

All Tools
Base64 to PDF
Local
Tool Details
Input formatsBASE64
Output formatPDF
Max file size100 MB
Max files1
ProcessingLocal

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. 1

    Upload Base64 file

    Select Base64 file from your device or drag file into the upload area.

  2. 2

    Review files

    Review the selected files and continue when they are ready.

  3. 3

    Convert to PDF

    Run the Base64 to PDF tool to create the PDF output.

  4. 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.pdf

PHP

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.

Original PDF size compared with its Base64-encoded length
Example filePDF sizeBase64 length
One-page invoice45 KB60 KB
Ten-page contract250 KB333 KB
Scanned passport page1.2 MB1.6 MB
Illustrated 40-page report8 MB10.7 MB
Full scanned manual32 MB42.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.pdf

On 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.pdf

Strips 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

How do I convert Base64 to PDF?
Upload a .txt or .base64 file containing the encoded PDF string, then run the converter. The tool decodes the Base64 value in your browser and downloads the result as a PDF file.
Can this decode a Base64 PDF data URL?
Yes. The converter accepts raw Base64 or the data:application/pdf;base64 prefix, removes whitespace, and checks that the decoded bytes begin with the PDF file signature.
Is the Base64 PDF uploaded?
No. This tool runs client-side, so the Base64 string and decoded PDF stay on your device.
How can I tell whether a Base64 string is even a PDF?
By its first six characters. A PDF starts with the bytes %PDF, which encode to JVBERi — so any base64 PDF begins that way. If yours starts with iVBORw it is a PNG, /9j/ is a JPEG, and UEsDB is a ZIP, which includes .docx and .xlsx files. A string starting with something else usually means the upstream system is sending the wrong field.
Why does my decoded Base64 PDF open as a blank or corrupt file?
Four causes account for almost all of it. The data:application/pdf;base64, prefix is still attached, so the leading characters corrupt the output — everything up to and including the first comma has to go. The string picked up line breaks from being logged or emailed. It is URL-safe base64, which uses - and _ where standard base64 uses + and /. Or it was truncated: a valid string’s length is always a multiple of 4, and a real PDF ends with %%EOF. This tool strips the prefix and whitespace for you and checks the file signature.
What if decoding produces something that looks like more Base64?
Then it was encoded twice, usually because one stage of a pipeline encoded a value that was already encoded. Letters, digits, + and / with no binary bytes in the output is the signature. Decode the result a second time.

Need More Tools?

Explore our collection of 58 free PDF tools, all with privacy-first processing.

Browse All Tools