← Blog
Base64 PDF Data URI

data:application/pdf;base64 Explained for Developers

Understand `data:application/pdf;base64,...` strings: what they mean, when to use them, when to strip the prefix, and when data URIs become a bad idea.

· GoGood.dev

If you have ever seen a string like data:application/pdf;base64,JVBERi0xLjQK..., you were looking at a data URI. It combines the file type, encoding format, and actual file contents into one long string.

TL;DR: A PDF Base64 data URI is just a PDF file encoded as Base64 with a MIME-type prefix. Strip the prefix before decoding in code.

Anatomy of a PDF data URI

data:application/pdf;base64,JVBERi0xLjQK...

Breakdown:

  • data: → this is a data URI
  • application/pdf → MIME type
  • ;base64 → content is Base64-encoded
  • , → separator
  • JVBERi0xLjQK... → actual file data

Why systems use data URIs

They are convenient because one field contains everything needed to reconstruct the file. You do not need separate metadata for MIME type if it is already embedded.

That is useful for:

  • HTML embeds
  • quick API payload transport
  • browser-only tools
  • test fixtures

Why they become annoying

For actual file workflows, they create three common problems:

  • strings get huge
  • developers forget to remove the prefix before decoding
  • logs and JSON payloads become harder to inspect

How to strip the prefix

JavaScript

const cleanBase64 = input.replace(/^data:[^;]+;base64,/, '');

Python

clean_base64 = value.split(',')[-1]

Node.js

const cleanBase64 = input.replace(/^data:[^;]+;base64,/, '');

When to use a data URI for PDFs

Usually only for transport or temporary browser usage.

Good fit:

  • short-lived previews
  • compact demos and test cases
  • all-in-one browser payloads

Bad fit:

  • large PDFs
  • persistent storage
  • logging-heavy systems
  • performance-sensitive APIs

FAQ

Is a PDF data URI different from plain Base64?

Yes. It includes the MIME-type prefix in front of the Base64 data.

Can I save a PDF directly from a data URI?

Yes, but most code first removes the prefix, decodes the Base64, then writes the bytes.

Why does my decoder fail on a data URI?

Because many decoders expect raw Base64 only.


Understanding the data URI format saves a lot of debugging time. If the string starts with data:application/pdf;base64,, the fix is usually simple: strip the prefix, decode, save. For fast manual checks, use GoGood.dev Base64 Converter.

Related: How to Convert Base64 to PDF Online · How to Decode Base64 to PDF Online · How to Convert Base64 Back to a File · How to Convert an Image to Base64 · When to Use Base64