JSON is a text format. It cannot contain raw binary data. Every developer who needs to send a PDF through a REST API eventually hits this wall and turns to Base64 encoding as the solution. The same problem appears in different forms: embedding a PDF directly in an HTML page without an external file, constructing a MIME email attachment block, or passing a document to a third-party API like Adobe Sign or DocuSign that expects base64-encoded file content in its request body. This browser-based tool encodes your PDF and outputs the result in six ready-to-use formats with code snippets in HTML, JavaScript, Python, PHP, and cURL. Nothing is uploaded to any server.
How It Works
- Upload your PDF: Click or drag the file into the drop zone. The file loads entirely in your browser. No data is transmitted to any external server at any point during encoding.
- Choose your output format and options: Select from six output formats: Raw Base64 (plain encoded string), Data URI (data:application/pdf;base64,... for embedding in HTML or CSS), HTML Embed (a ready-to-paste <embed> tag), JSON Object (structured with data and type fields for API payloads), Email MIME (RFC 2045 compliant attachment block for email construction), or CSS/JS Variable (const or var assignment ready to paste into code). Set line wrapping (64-character MIME standard, 76-character RFC 2045, or no wrapping). Toggle URL-safe encoding to replace + and / with - and _ for use in URLs or JWT tokens. Optionally strip trailing padding characters or include a size checksum.
- Copy or download the output: The browser reads your PDF as a binary array buffer, encodes it using the Web Crypto API's base64 algorithm, and applies your chosen format wrapper and line-wrapping rules. Copy the output string directly to your clipboard or download it as a text file. Scroll down to the code snippets section to see exactly how to use the encoded string in your target language.
Compatibility and Support
Supported Input and Output Formats
- Input: Any PDF file regardless of content (text, images, forms, scanned pages)
- Output formats: Raw Base64 string, Data URI for HTML/CSS embedding, HTML <embed> tag, JSON object payload, RFC 2045 MIME email block, CSS/JavaScript variable assignment
- Encoding variants: Standard Base64 (RFC 4648) and URL-safe Base64 (replaces + with - and / with _)
- Code snippets provided: HTML, JavaScript, Python, PHP, cURL/API
Unsupported Formats
- Non-PDF inputs are not accepted directly. If you need to encode a different file type, convert it to PDF first.
- Base64 encoding adds approximately 33% to the file size. A 1MB PDF becomes roughly 1.37MB when encoded. Very large PDFs encoded as Data URI strings can cause browser rendering issues when embedded directly in HTML pages; for PDFs over 5MB, serving the file from a URL and referencing it via <embed src> is the better approach.
File Size Limits
There is no server-side file size cap since all encoding runs in your browser. The practical constraint is your device's available memory. For most use cases, PDFs under 10MB encode without issue. Very large PDFs can produce extremely long output strings that may strain text editors or clipboard operations on older machines.
Who Should Use This Tool?
- Students: A web development student learning to work with APIs who needs to understand how binary file data gets passed through JSON requests. The side-by-side output formats and code snippets make the mechanics of base64 encoding immediately visible without having to set up a development environment.
- Freelancers: A freelance web developer building an HTML email template that needs to include a PDF attachment inline as a MIME block rather than as an external file link. The Email MIME output format writes the complete RFC 2045 attachment structure ready to paste into the email construction code.
- Office Professionals: A business analyst on an automation team who needs to pass a PDF report to a third-party document signing API. The API expects a JSON payload with a base64-encoded file field. The JSON Object output format produces exactly that structure, and the cURL snippet shows how to send it.
- Developers: A backend developer integrating a document generation service that returns PDFs and needs to re-encode them for a downstream API call within a JavaScript or Python function. The URL-safe encoding option matters here if the base64 string will be included in a URL parameter or embedded in a JWT token where standard + and / characters cause parsing errors.
Key Features
Here's what separates this tool from generic alternatives:
Six Output Format Options
Raw string, Data URI, HTML embed, JSON object, MIME email block, and CSS/JS variable assignment cover every real-world use case in a single conversion.
Code Snippets in Five Languages
HTML, JavaScript, Python, PHP, and cURL examples show exactly how to use the encoded output in your target environment, saving the lookup time.
URL-Safe Encoding Option
Switches + to - and / to _ for use in URL parameters, JWT tokens, or any context where standard base64 characters cause parsing errors.
100% Browser-Based, No Upload
PDF encoding runs entirely in your browser. Confidential documents, legal files, and API payloads containing sensitive data never leave your device.
Configurable Line Wrapping
Set wrapping at 64 characters (MIME standard), 76 characters (RFC 2045), no wrapping for APIs that expect a single-line string, or a custom column width.
Optional Checksum Verification
Enable the size checksum to append a verification hash to the encoded output, useful for validating that the encoded string was not corrupted during transmission.
Why This Tool Beats the Alternatives
- No account creation, no rate limits, no daily encoding quota
- No watermarks or promotional strings injected into the encoded output
- No server upload; generic online base64 tools send your file bytes to a remote server, which defeats the purpose of encoding confidential documents for secure transmission
- Six output formats versus the single raw-string output most base64 converters provide
- Built-in code snippets in five languages instead of requiring a separate documentation lookup
- URL-safe encoding toggle, padding removal, line wrapping, and checksum all in one interface
Pro Tips
- If your target API keeps returning a bad request error when you send the base64-encoded PDF, check whether it expects a raw string or a Data URI. Many APIs want just the encoded bytes without the data:application/pdf;base64, prefix. Use the Raw Base64 format in that case, and strip any line breaks if the API documentation says the string must be on a single line.
- For embedding a PDF directly in a web page using a Data URI, test the page in your browser's developer tools before deploying. Browsers handle inline PDFs differently: Chrome renders the Data URI inline as a PDF viewer, while some mobile browsers download it instead. For reliable cross-browser behavior, use an <iframe> with the src set to the Data URI rather than an <embed> tag.
- When constructing MIME email attachments, the line-wrapped 76-character RFC 2045 format is correct for SMTP transmission. If you are using an email API like SendGrid or Mailgun that accepts base64 in a JSON field, those APIs typically want the raw unwrapped string instead. Select the appropriate wrapping setting before copying the output to match what your email system expects.
Drop your PDF in, pick your output format, copy the encoded string, and paste it directly into your code. To go the other direction and recover a PDF from a base64 string, the Base64 to PDF converter decodes it back in the same browser-based way, and the Base64 Decoder/Encoder handles general-purpose encoding and decoding for any input.