Convert PDF to Base64
PDF (Portable Document Format) is the standard for documents that must render identically everywhere. This tool converts PDF files to Base64 strings for use in API requests, database storage, email attachments, and inline HTML embedding.
How to Use
- Drop a PDF file onto the upload area or click to browse
- The tool reads the file locally and encodes it
- Choose output format: plain Base64 (most common for PDFs), data URI, or CSS background
- Copy the result
Common Use Cases
REST API document uploads
Many APIs accept PDF uploads as Base64 encoded strings in JSON payloads. This avoids the complexity of multipart form data:
{
"document": "JVBERi0xLjQKMSAwIG9iago8PAovVHlwZS...",
"filename": "invoice.pdf",
"contentType": "application/pdf"
}
Services like DocuSign, Adobe Sign, Twilio SendGrid (for email attachments), and cloud storage APIs commonly support this pattern.
Database storage
Storing PDFs as Base64 text in a database column avoids dealing with binary blob types. This approach works for small documents (contracts, receipts, certificates) where the simplicity of text storage outweighs the 33% size overhead. For large document volumes, binary storage or object storage (S3) is more efficient.
Email attachments via API
When sending emails programmatically through APIs like SendGrid, Mailgun, or AWS SES, attachments are typically Base64 encoded:
{
"attachments": [{
"content": "JVBERi0xLjQK...",
"filename": "report.pdf",
"type": "application/pdf"
}]
}
Inline HTML embedding
PDF viewers can render Base64 data URIs:
<iframe
src="data:application/pdf;base64,JVBERi0xLjQK..."
width="100%"
height="600px"
></iframe>
This creates a self contained page with an embedded PDF. Browser support is generally good, but large PDFs may cause performance issues, and mobile browsers often do not support inline PDF rendering.
PDF File Size Considerations
PDFs range from a few kilobytes (simple text documents) to hundreds of megabytes (high resolution image heavy documents). After Base64 encoding:
| PDF type | Typical size | Base64 size |
|---|---|---|
| Text only (1-2 pages) | 10-50 KB | 13-67 KB |
| Text with images (10 pages) | 200 KB-2 MB | 267 KB-2.7 MB |
| Scanned document (50 pages) | 5-20 MB | 6.7-26.7 MB |
| High res graphics | 50+ MB | 67+ MB |
For API payloads, most services impose request size limits (often 10 MB or 25 MB). If the Base64 encoded PDF exceeds the limit, you will need to use multipart upload or upload to object storage and pass a reference URL instead.
PDF Magic Bytes
PDF files always begin with %PDF (hex: 25 50 44 46). In Base64, this becomes JVBERi. This tool detects the MIME type from these signature bytes, so even if the file has an incorrect extension, the data URI will use application/pdf.
The PDF version follows immediately: %PDF-1.4, %PDF-1.7, %PDF-2.0. Higher versions support more features (layers, 3D objects, rich media), but all begin with the same %PDF signature.
Security Considerations
PDFs can contain JavaScript, form actions, and external links. Base64 encoding does not sanitize or modify the PDF content in any way. It is a byte for byte encoding. If you are accepting Base64 encoded PDFs from untrusted sources, run them through a PDF sanitizer before processing or rendering.
To convert a Base64 string back to a downloadable PDF, use Base64 to PDF. For text encoding/decoding, see the main Base64 Encoder. For file integrity verification, the Hash Generator can compute SHA-256 checksums of your PDF files.