Where do Base64 PDFs come from?
Base64 writes any file using only letters, digits and a few symbols, so it can travel inside text. That is why PDFs often turn up as a long string instead of a file:
- API responses. E-invoice, shipping label, payment receipt and e-signature services usually return the PDF as a Base64 field in JSON or XML.
- Web forms and databases. Some systems store uploaded documents in a text column, and an export gives you the code, not the file.
- Email source. In the raw source of an email, attachments are Base64 blocks under a Content-Transfer-Encoding: base64 header.
- Developer testing. When your own code produces a Base64 PDF, this is a quick way to see whether the result is the document you expected.
Where to find the code and how to copy it in full is explained step by step in How to save a Base64 string as a PDF file. For the same job with pictures, see Base64 to image. To go the other way and get the code of a PDF, use PDF to Base64.
How to recognise what is inside
| The code starts with | What it is | Where to go |
|---|---|---|
| JVBERi0 | PDF document | This page |
| data:application/pdf;base64, | PDF document (data URI) | This page |
| iVBORw0KGgo | PNG picture | Base64 to image |
| /9j/ | JPG photo | Base64 to image |
| UEsDB | ZIP, Word (.docx) or Excel (.xlsx) | Not a PDF |
If something goes wrong
"This is not valid Base64 code." Some other text got mixed into the code, or the copy stopped halfway. Select the whole value between the quotation marks and paste it again.
"What is inside is not a PDF." You probably copied a neighbouring field — a file name, an ID or a signature hash. Look for the value that starts with JVBERi0.
The PDF opens but some pages are blank. The end of the code is missing: the first pages were decoded, the rest was not there. Copy the code again in full; in long JSON files, using the viewer's "copy value" option is safer than selecting by hand.
The PDF asks for a password. The document was protected before it was encoded. If you know the password, you can remove it with Unlock PDF.