Skip to content
FormatKit

Free online Base64 to PDF converter

Base64 to PDF that checks the header first

Paste the string and the document is rebuilt in this tab — free, with no account, up to 8 MB of Base64 — but nothing is offered for download until the decoded bytes are shown to start with %PDF-. That one check is the difference between a file you can open and a file that fails silently, because the most common thing in a broken PDF pipeline is not a broken PDF: it is a JSON error body, an HTML login page or a data: prefix that was never stripped. What you get instead of a guess is the version from the header, the page count, the page size in millimetres, the producer that wrote it, and a list of every repair the string needed on the way in.

  • 100% free
  • No signup
  • Up to 8 MB of Base64
  • %PDF- header verified
  • Page count and size
The file

The document appears here once the string decodes to something starting with %PDF-.

Nothing pasted yet. Sample PDF builds a one-page document in the box so you can see the checks run.

How to turn Base64 back into a PDF

Paste it, read what the file says about itself, save it.

  1. Paste the string as you found it

    Straight out of the API response, the log line or the database column — the surrounding quotes, a data:application/pdf;base64, prefix, escaped slashes from a JSON field, line breaks from a terminal and the URL-safe alphabet are all handled. Every repair is listed under the output, so the string that needed six of them tells you something about the pipeline it came through.

  2. Read the verdict before the file exists

    The right panel only fills in once the decoded bytes begin with %PDF-. It shows the version from the header, the size, the page count and where that count came from, the page dimensions in points and millimetres, and the producer that wrote the file. If the bytes are something else entirely — a JSON error body is the usual culprit — the page names what they actually are instead of handing you a file that will not open.

  3. Open it or save it

    Open hands the blob to the browser's own PDF viewer in a new tab, which is the same renderer that will display the saved file. Download writes it under the name in the toolbar, adding .pdf if you left it off. Both work from the bytes already in the page — nothing is fetched, and nothing was sent to produce them.

Technical specifications

Maximum input8,388,608 Base64 characters, carrying a document of up to 6 MB (6,291,456 bytes)
Cleaned up before decodingSurrounding double quotes, \/ and \n JSON escapes, a data:…;base64, prefix, all whitespace and line wrapping, the URL-safe alphabet, and missing = padding — each repair listed individually
Header checkThe decoded bytes must begin with %PDF- (25 50 44 46 2D); the version digit pair is read out and shown, and anything else is identified rather than saved
Read from the documentPDF version, byte size, page count with its source, first /MediaBox in points and millimetres, /Producer or /Creator, /Encrypt and /Linearized flags, and whether the file ends in %%EOF
Page count accuracyTaken from the largest /Count in the page tree, or from /Type /Page objects when there is none. A file whose page tree lives in a compressed object stream reports “unknown” rather than a wrong number
Inline previewThe first embedded JPEG stream is extracted and rendered, which covers scanned documents; vector PDFs open in the browser's own viewer in a new tab instead
Rejections explainedA mixed alphabet, a 4n+1 length, a stray % escape, a data: URI with no ;base64 marker, and the position of the first character outside the alphabet
Price and processingFree with no signup; decoding, inspection and the download all happen in this tab, and the document is never uploaded

Frequently asked questions

The file downloads but will not open. What is wrong?

Almost always that the bytes are not a PDF, and the five characters at the front settle it in an instant. Every PDF since version 1.0 begins with %PDF- followed by a version number, so a file that does not is something else wearing a .pdf name — most often a JSON error body, an HTML login page, or a ZIP that a document API returned when it could not produce the document. This page checks that header before it offers you anything to save, and when it fails it decodes the first bytes as text and tells you what arrived.

Why does my string start with data:application/pdf;base64,?

Because it was written for a browser rather than for a decoder. That prefix is the data: URI syntax from RFC 2397, and it is how an API or a JavaScript library hands over a document that can be dropped straight into a link or an iframe. It is not part of the Base64 and must be removed before decoding — feeding it to a decoder produces bytes that begin with the letters of the word data, which is exactly why so many rebuilt PDFs open to an error. The prefix is stripped here automatically, and the media type it declared is reported in case it was not application/pdf.

My Base64 came out of a JSON field and is full of backslashes.

Those are JSON escapes and they have to come off first. A JSON string writes a forward slash as either / or \/ — both are legal, and plenty of PHP and Java serialisers still choose the escaped form — so a Base64 payload from a JSON field arrives with \/ wherever it had /. Copying the field with its surrounding quotes brings those along too, and a pretty-printed response may have inserted \n. All three are stripped here before decoding, and each one is listed so you can see what the serialiser did.

Why does the page say the PDF has no %%EOF?

Because the string stopped early. A PDF ends with a cross-reference offset and the literal marker %%EOF; when that is missing, the file was cut rather than corrupted, and the cut almost always happened before the Base64 ever reached you — a database column with a length limit, a log line truncated at a column width, a copy that missed the last screenful. Some readers repair a truncated file by rebuilding the cross-reference table and some refuse it, so the download stays available and the warning tells you not to trust it. Fetch the value again from a place that does not truncate.

Why can I see a picture of some PDFs here and not others?

Because a scanned page is a photograph inside the file and a generated page is not. Scanners store each page as a JPEG stream, byte for byte, inside the PDF — so the first JPEG can be lifted out and shown without a PDF renderer at all, which covers most invoices, receipts and signed contracts. A document produced by a word processor or a reporting library draws its pages from vector operators and embedded fonts, and rendering that genuinely requires a PDF engine. For those, Open hands the file to the browser's own viewer in a new tab.

The decoded bytes are JSON, not a PDF. What happened?

The service failed and encoded its failure. An endpoint that returns a document as a Base64 field often returns an error object through the same field on a bad day, so what you decode is {"error":"not_authorised"} rather than a document — and because it is valid Base64, every decoder happily produces it. The page reads the first bytes and says so. Decode it as text to see the message: the error body usually names the cause precisely, which the eventual PDF reader error never will.

The document is encrypted. Will the rebuilt file still work?

Yes — the bytes are reproduced exactly, and the password is still needed to read them. Base64 wraps a file for transport; it is not a lock, and decoding it removes nothing. When the document carries an /Encrypt dictionary this page says so before you download, so the viewer asking for a password afterwards is expected behaviour rather than a sign the conversion went wrong. Whoever issued the document has the password; nothing on this page can derive it.

About rebuilding a PDF from Base64

A PDF is one of the few binary formats you can reason about by looking at it, and that is what makes verification cheap here. The file opens with %PDF-1.4 or similar, then a body of numbered objects, then a cross-reference table listing the byte offset of every one of them, then a trailer naming the root object, and finally the literal %%EOF. Two of those are worth checking before anything else: the header, because five bytes decide whether you are holding a document at all, and the trailer, because its absence means the file was cut rather than mangled. Between them, the page tree carries a /Count and each page a /MediaBox in points at 72 to the inch — which is how a 595 × 842 box turns out to be A4.

What happens to a PDF between a server and your clipboard is remarkably consistent. It is put in a JSON field, so its slashes may come back escaped and the whole value arrives inside quotes. It is written for a browser, so it acquires a data:application/pdf;base64, prefix that is part of the URI and not part of the payload. It passes through a terminal or an email, so it is wrapped into lines. It travels in a URL, so it is written in the base64url alphabet with - and _. And it is stored in a column that turns out to be too short, so it loses its tail. Each of those is reversible except the last, and each one is listed here as it is undone, because knowing which repair was needed usually identifies the layer that did the damage.

The page count deserves one caveat. Since PDF 1.5 a writer may pack objects into a compressed object stream, and when the page tree ends up in one the count cannot be read without inflating it — so this page reports “unknown” rather than a number it guessed at, and a lower bound is never presented as a total. The inline preview has a similar honesty problem, solved differently: scanned pages are stored as JPEG streams and can be pulled out and shown directly, while a vector document needs a full renderer, so it is handed to the browser's own viewer instead. If it turns out the string was never a PDF, the general decoder identifies what it really is, and the file encoder builds the string in the other direction when you need to reproduce the problem.

Where the document is rebuilt

In the tab in front of you. The Base64 becomes bytes in JavaScript memory, the bytes become a blob that only this tab can address, and the download link points at that blob — at no stage is a request made or a copy left anywhere. Invoices, payslips and signed agreements are the everyday contents of a Base64 PDF, so the tool is built to work with the network switched off.