Encode a PDF to Base64
- Dashboard
- Documentation
- API
Encode a PDF in Base64
Base64 is an encoding that represents binary data as ASCII text (64 characters: A-Z, a-z, 0-9, plus two additional characters). A PDF file, which is binary by nature, cannot be pasted directly into an HTML email, a JSON payload or an XML attribute: it must first be converted to text. Our tool takes your PDF file and returns its Base64 representation, ready to be copied.
For details on Base64 and the Data URI format in general, see our Base64 text encoder which covers the principles in depth.
Why encode a PDF in Base64?
- Embed a PDF in an HTML email: some email clients accept Data URI links or inline MIME-encoded attachments.
- Store a PDF in a database text field (
TEXTorVARCHARcolumn) when the application constraint prohibits a binary type (BLOB). - Transmit a PDF in an API JSON payload: JSON does not support binary, so any file must transit in Base64.
- Embed a PDF in a data: URL: rare usage, to be reserved for very small files, because URLs have length limits (typically 2000 to 8000 characters depending on browser and server).
Data URI format for PDF
A Data URI type URL embeds the PDF content directly in the URL:
data:application/pdf;base64,JVBERi0xLjQKJcfsj6IKNSAwIG9iago8PC9MZW5ndGggNiAwIFI...
The data:application/pdf;base64, prefix tells the browser the MIME type and encoding. You can paste this URL directly into a modern browser's address bar to open the PDF, or place it in the src attribute of an <iframe> or <embed>.
Concrete use cases
- Electronic signatures: most signature APIs (DocuSign, Yousign, etc.) accept or require the PDF in Base64 in the JSON body of the request.
- Backups and archiving: serialize a PDF in a JSON export or a git-versioned text file (avoid for large volumes, but practical for test fixtures).
- Automated tests: integrate a reference PDF directly into a unit test without depending on an external file.
- Client exports: generate a PDF server-side, return it in Base64 in the JSON response, the client decodes it and downloads it without an additional HTTP call.
Disadvantages to know
- Size overhead: Base64 adds about 33% to the volume. A 1 MB PDF becomes a 1.37 MB string in Base64.
- No HTTP cache: a PDF embedded in Data URI in an HTML page is re-downloaded at each load, unlike a file served from a classic URL with cache headers.
- Size limits: browser memory, maximum server-side POST size (
upload_max_filesizeandpost_max_sizein PHP), and database quotas (MySQL row size, for example) can quickly be exceeded on large PDFs. - Not suitable for large files: beyond a few MB, prefer dedicated storage (S3, disk) and transmit a URL rather than encoded content.
How to use the tool
- Click on the upload field and select your PDF file.
- The tool encodes the binary content into Base64 and displays the result.
- You can choose whether or not to include the
data:application/pdf;base64,prefix depending on your use case (with prefix for a Data URI, without prefix for a JSON payload). - Copy the string and paste it where you need it.
Frequently asked questions
What is the maximum accepted PDF size?
The limit depends on the server configuration. In practice, stay under a few MB to keep the experience fluid. Beyond that, the browser slows down, the clipboard saturates, and destinations (email, JSON, database) risk rejecting the payload.
Is Base64 PDF compatible with email clients (Gmail, Outlook)?
As an inline-encoded attachment in a MIME message, yes: it is even the standard mechanism for email. On the other hand, in a Data URI in the HTML body of a message (<a href="data:..."> or <iframe>), most email clients block or rewrite these URLs for security reasons. Prefer the classic attachment.
What difference with an encrypted PDF?
Encoding in Base64 is not encrypting: the string remains readable and trivial to decode by anyone. An encrypted PDF (owner or user password) remains encrypted even after Base64 encoding: encoding and encryption are two independent operations.
Can I do the reverse operation?
Yes: use our Base64 PDF decoder to transform a Base64 string into a downloadable PDF file.
Is my PDF sent to your servers?
Encoding is processed server-side for the duration of the request, then the file is released. No persistent storage is performed. For particularly sensitive PDFs, prefer local processing with an offline tool.
Example request
curl -X POST https://cdrn.fr/api/v1/tools/base64-pdf-encoder/execute \
-F "file=@/path/to/file"
Input schema
| Field | Type | Required | Default |
|---|---|---|---|
file |
file | ✓ | – |
this tool expects a file - use Content-Type multipart/form-data instead of application/json
Endpoints
GET https://cdrn.fr/api/v1/tools- lists every available toolGET https://cdrn.fr/api/v1/tools/base64-pdf-encoder- returns the schema for this toolPOST https://cdrn.fr/api/v1/tools/base64-pdf-encoder/execute- runs this tool with a JSON payload