When do you need a PDF as Base64?
JSON, XML and many forms can only carry text, so a binary file such as a PDF has to be written as text first. Base64 is the usual way to do it:
- Sending a document to an API. E-invoice, e-signature, shipping and document-management services often ask for the PDF in a field called content, file or data.
- Testing your own integration. With the JSON option you get a ready request body to paste into Postman, curl or a unit test, without writing any encoding code.
- Storing in a text column or config. Some systems keep small templates or certificates as text; Base64 makes the PDF fit.
- Embedding in a web page. A data URI lets a page show a PDF in an iframe without hosting a separate file — fine for small documents.
Step-by-step request examples in curl, JavaScript and Python are in How to send a PDF to an API as Base64. To turn the code back into a file, use Base64 to PDF; for pictures, see Image to Base64.
What each format looks like
| Format | Starts with | Typical use |
|---|---|---|
| Base64 code only | JVBERi0 | API fields, JSON, XML, databases |
| Data URI | data:application/pdf;base64, | Browser tab, iframe, object tag |
| 76-character lines | JVBERi0, broken into short lines | Email attachments (MIME), PEM-style files |
| JSON | { "fileName": … } | Request body for testing an integration |
If something goes wrong
"This file is not a valid PDF." The file does not start with the %PDF- signature — it may be a Word file or an image renamed to .pdf. Open it in a PDF reader first, or convert it with the right tool.
The API says the content is invalid. Check that you sent the bare code without the data: prefix and without line breaks, unless the documentation asks for them. Also make sure nothing was cut off at the end when you pasted.
The text is too long for the field. Make the PDF smaller with Compress PDF and convert it again; the code shrinks by the same proportion.