Base64 to PDF Decoder

Paste Base64 or a PDF data URI — preview and download. Processing stays in your browser — nothing is uploaded.

How to decode Base64 to PDF

  1. Paste your Base64 string into the input area — plain Base64 or a full data URI (data:application/pdf;base64,…) both work. Whitespace and line breaks are stripped automatically.
  2. The tool validates the decoded bytes against the PDF magic header (%PDF). If the string is not a valid PDF, an error explains the likely cause.
  3. Preview the PDF inline using your browser's built-in viewer — no file is saved to disk yet. Scroll through to confirm it is the correct document before downloading.
  4. Click Download PDF to save the file. Or use Copy data URI to get the full data:application/pdf;base64,… string for use in HTML or JavaScript.

Where you encounter Base64-encoded PDFs

{}
REST API responses
Document generation APIs (invoices, reports, contracts) commonly return PDFs as Base64 strings inside a JSON field rather than as a binary file download. The response body looks like { "pdf": "JVBERi0x…" }. Paste the field value here to preview or download the PDF.
@
Email MIME attachments
Email attachments are encoded using Base64 as part of the MIME multipart format. The Content-Transfer-Encoding: base64 header indicates the body is encoded. If you are debugging raw email source or processing emails via an API like Gmail or SendGrid, the attachment data you receive is Base64.
Database TEXT columns
Some architectures store PDFs directly in a database TEXT or BLOB column as Base64 rather than on a file server. When reading from the database for debugging, you get the raw Base64 string. Paste it here to verify the stored file is a valid, uncorrupted PDF.
Webhook payloads
E-signature platforms (DocuSign, HelloSign), payment providers, and document services often include signed or generated PDFs as Base64 fields in webhook POST bodies. Use this tool to inspect the payload PDF during integration development.
</>
HTML data URIs
A data URI in the form data:application/pdf;base64,<string> can be pasted directly — the tool strips the prefix automatically. You might encounter these in HTML source, JavaScript variables, or browser DevTools network responses.

How to recognise a Base64-encoded PDF

Two patterns identify a Base64 PDF at a glance:

Plain Base64
JVBERi0x…
Always starts with JVBERi0 — the Base64 encoding of the ASCII bytes %PDF (0x25 0x50 0x44 0x46). If your string starts with these 7 characters, it is a Base64 PDF.
Data URI
data:application/pdf;base64,JVBERi0x…
The MIME type prefix declares the content type explicitly. Paste the entire data URI — the tool strips the prefix automatically before decoding.

Fixing common decode errors

Nearly every decode failure comes from one of four causes. Here is how to diagnose and fix each one.

Missing or incorrect paddingmost common
Symptom: Error: Invalid Base64 — check for typos or truncated paste.

Cause: Base64 output length must be a multiple of 4 characters. When the source byte count is not divisible by 3, one or two = padding characters are appended. Some systems strip padding when storing or transmitting Base64. A string of length 4n+1 is always invalid; 4n+2 needs == appended; 4n+3 needs = appended.

Fix: Add the missing = characters to the end of the string until its length is a multiple of 4, then paste again. Most decoders (including this one) handle missing padding automatically, but some pipelines produce truncated strings that need manual repair.

Broken
JVBERi0xLjQKJcfs4AAQ
Fixed
JVBERi0xLjQKJcfs4AAQ==
Whitespace and newlines in the string
Symptom: Error: Invalid Base64 — or silent corruption if the decoder does not strip whitespace.

Cause: MIME Base64 (RFC 2045) inserts a line break every 76 characters for email compatibility. When you copy a Base64 PDF from email source, a multipart body, or some APIs, the string contains embedded newlines (\n or \r\n). Standard Base64 (RFC 4648) does not allow whitespace.

Fix: This tool strips whitespace automatically before decoding. If you are decoding in code, remove whitespace first: b64.replace(/\s/g, "") in JavaScript, or b64.strip() in Python.

Broken
JVBERi0xLjQK
Jcfs4AAQ==
WVBERi0x...
Fixed
JVBERi0xLjQKJcfs4AAQ==WVBERi0x...
URL-safe Base64 instead of standard Base64
Symptom: Decoded bytes fail the %PDF check — document renders as garbage.

Cause: RFC 4648 defines two Base64 variants. Standard Base64 uses + and / as the 62nd and 63rd characters. URL-safe Base64 (Base64url) replaces these with - and _ to avoid conflicts in URLs and JSON Web Tokens. If your string contains - or _, it is URL-safe and needs conversion before standard decoding.

Fix: Replace all - with + and all _ with / before pasting, then add padding if needed. In code: b64.replace(/-/g, "+").replace(/_/g, "/").

Broken
JVBERi0xLjQKJcfs-AAQ_Wg==
Fixed
JVBERi0xLjQKJcfs+AAQ/Wg==
Truncated string — only part of the PDF was copied
Symptom: Decoded bytes do not start with a PDF signature (%PDF).

Cause: Large Base64 strings are often truncated when copied from log viewers, API explorers, or terminal output that cap display length. A PDF that is 1MB will encode to approximately 1.4 million Base64 characters — easy to accidentally copy only part of.

Fix: Copy the full Base64 value programmatically rather than from a display. In curl output, redirect to a file. In API explorers, use the raw response view and copy the entire field value.

Broken
JVBERi0xLjQK... [truncated in log viewer]
Fixed
// Fetch the full value programmatically:
const response = await fetch("/api/generate-pdf")
const { pdf } = await response.json()
// pdf is the complete Base64 string

Decoding Base64 PDF in code

Use this tool to verify a Base64 string visually. When you are ready to handle decoding in your own application, here are the standard approaches.

Node.js
// Decode Base64 PDF and save to disk
const fs = require('fs')

const base64String = 'JVBERi0xLjQ...' // your Base64 string
const buffer = Buffer.from(base64String, 'base64')
fs.writeFileSync('output.pdf', buffer)

// Or decode a data URI:
const dataUri = 'data:application/pdf;base64,JVBERi0xLjQ...'
const raw = dataUri.split(',')[1]
const buf = Buffer.from(raw, 'base64')
fs.writeFileSync('output.pdf', buf)
Python
import base64

base64_string = 'JVBERi0xLjQ...'  # your Base64 string

# Add padding if needed
padding = 4 - len(base64_string) % 4
if padding != 4:
    base64_string += '=' * padding

pdf_bytes = base64.b64decode(base64_string)

with open('output.pdf', 'wb') as f:
    f.write(pdf_bytes)
PHP
<?php
$base64String = 'JVBERi0xLjQ...'; // your Base64 string
$pdfBytes = base64_decode($base64String);

file_put_contents('output.pdf', $pdfBytes);

// Verify it is a real PDF
if (substr($pdfBytes, 0, 4) !== '%PDF') {
    throw new Exception('Decoded data is not a valid PDF');
}

Related tools

Frequently asked questions

Is my Base64 data sent to a server when I decode it?

No. Decoding runs entirely in your browser using JavaScript. The Base64 string you paste is processed in memory and never transmitted over the network. The PDF preview uses a local blob URL created by your browser — no file is uploaded or stored anywhere.

How can I tell if a string is a Base64-encoded PDF before decoding?

A Base64-encoded PDF always starts with JVBERi0 — this is the Base64 encoding of %PDF, the magic header required by every valid PDF file. If your string starts with data:application/pdf;base64, it is a PDF data URI and you can paste it directly. If neither pattern matches, the string is either not a PDF or was encoded with a different method.

Why does decoding fail with "does not start with a PDF signature"?

This error means the decoded bytes do not begin with %PDF. Common causes: (1) the string is URL-safe Base64 using - and _ instead of + and / — replace them before pasting; (2) the string is truncated — only part of the PDF was copied; (3) the original file is not a PDF — it may be a Word document, image, or other binary file that was incorrectly assumed to be a PDF.

The PDF preview does not appear. What can I do?

In-browser PDF preview uses a blob URL and your browser's built-in PDF viewer. Safari on iOS does not support inline PDF rendering via blob URLs — use the Download button instead and open the file in Files or a PDF app. Some corporate browsers with strict Content Security Policies may also block blob URLs. In both cases, the download still works.

What is Base64 padding and why does it matter?

Base64 encodes 3 bytes at a time into 4 characters. When the input length is not divisible by 3, padding characters (=) are appended to make the output length a multiple of 4. A string ending in = has 1 padding character (2 remaining input bytes); == has 2 (1 remaining byte). Many systems strip padding when storing Base64. If your string length modulo 4 is 2, add ==; if it is 3, add =. This tool handles missing padding automatically.

What is the difference between plain Base64 and a data URI?

A plain Base64 string is just the encoded bytes — for example JVBERi0xLjQ.... A data URI wraps the Base64 with a MIME type prefix: data:application/pdf;base64,JVBERi0xLjQ.... Data URIs are used in HTML src attributes and browser JavaScript. APIs and most backend systems use plain Base64. This tool accepts both — it automatically detects and strips the data URI prefix if present.

Can I decode a Base64 PDF that was encoded with URL-safe Base64?

Yes, but you need to convert it first. URL-safe Base64 (RFC 4648 Section 5) replaces + with - and / with _. This variant is used in JSON Web Tokens (JWT), URL parameters, and some file storage APIs. Replace all - with + and all _ with / in your string, add any missing = padding, then paste the result into this tool.

The downloaded PDF opens but shows blank pages or garbled content. Why?

This usually means the Base64 string was truncated — only part of the PDF was decoded. PDFs are structured binary files and a partial decode produces a syntactically invalid file that browsers render as blank. Verify the full Base64 string length is correct: a 1MB PDF encodes to approximately 1,398,101 characters. If the string is shorter than expected, fetch the complete value programmatically rather than copying from a display.