How to Convert PDF to Base64
Choose a file and the tool reads its bytes in your browser and encodes them as Base64 text. Every PDF starts with %PDF-, so its Base64 starts with JVBERi0. The sample PDF in the tool, a 599 byte file, becomes 800 characters that begin like this:
JVBERi0xLjQKMSAwIG9iago8PCAvVHlwZSAvQ2F0YWxvZyAvUGFnZXMgMiAw...Convert PDF to Base64 Online: Output Formats
- Base64: the plain string, on one line or with a line break every 76 characters as email uses.
- URL-safe Base64: uses
-and_instead of+and/and drops the=padding, for URLs and file names. - Data URI:
data:application/pdf;base64,...for HTML or a browser address. - JSON field: an object with filename, contentType and content keys.
- HTML embed and HTML iframe: a tag that shows the PDF in a web page.
- cURL request: a POST command with the JSON body and a placeholder URL.
Put a Base64 PDF in a JSON Request
Most APIs that accept files in JSON want the Base64 string in a text field. The JSON field format gives you this, with the file name filled in:
{"filename": "invoice.pdf", "contentType": "application/pdf", "content": "JVBERi0xLjQK..."}Base64 only uses letters, digits, +, / and =, so it needs no escaping inside a JSON string. If you need to escape other text for JSON, use JSON Escape.
How Much Bigger Is the Base64 String?
Base64 turns every 3 bytes into 4 characters, so the text is about one third larger than the file. The tool shows the exact numbers:
- 1,024 bytes become 1,368 characters (+33.6%).
- 102,400 bytes become 136,536 characters (+33.3%).
- 1,048,576 bytes become 1,398,104 characters (+33.3%).
Line breaks add one more character every 76. Strings over 1 MB get a warning because many APIs limit request size.
Raw Base64 or a Data URI
Raw Base64 is only the encoded bytes. A data URI adds data:application/pdf;base64, in front, which tells a browser what kind of file it is. Use raw Base64 for APIs and databases, and a data URI when the browser has to show the file. To turn either back into a PDF, use Base64 to PDF.
Convert a PDF to Base64 in Your Own Code
If you need to do the same in a script, the steps are short. Use this tool to compare your output: the same file must give the same string.
import base64
with open("invoice.pdf", "rb") as f:
b64_text = base64.b64encode(f.read()).decode("ascii")import { readFileSync } from "node:fs";
const b64Text = readFileSync("invoice.pdf").toString("base64");Both give plain Base64 on one line, the same as the Base64 format here with line breaks off. Add data:application/pdf;base64, in front if the receiver wants a data URI.
When Not to Use Base64 for a PDF
Base64 is for places that only accept text. If an API offers a multipart file upload, send the file itself: it is a third smaller on the wire and nothing has to be decoded. Embedding a large PDF in a web page as a data URI also slows the page, because the text must load before anything else that follows it. This tool accepts PDFs up to 10 MB, and it does not compress or edit the file.
Your PDF Stays in Your Browser
The file is read and encoded in your browser tab. It is not uploaded and not stored. See the Privacy Policy for details. For pictures, use Image to Base64, and for plain text use Base64 Encode.