Convert PDF to Base64

Drop a PDF file to get its Base64 string or a ready-to-paste Data URI — encoded locally, never uploaded.

Input — PDF file○ Waiting for input

Drag & drop a PDF here

or

Your files and data stay in your browser.

Inspection Report

File metadata
Detected Type
MIME Type
Encoding
Input Length
Decoded Size
Padding Status
Data URI
File Signature
Preview Availability

How to convert PDF to Base64

To convert a PDF to Base64, drag and drop the file onto the tool above (or use Choose File). The PDF is read and encoded entirely in your browser, and you can copy the result as plain Base64 or as a data:application/pdf;base64,... Data URI. The file never leaves your device.

How to Use

  1. Drag your PDF onto the drop zone, or click Choose File and pick it. Drag and drop is never the only way to add a file.
  2. The tool checks the file really is a PDF and shows its name, size and page-ready metadata in the inspector.
  3. Pick an output tab: plain Base64, Data URI, JavaScript or Python.
  4. Click Copy to copy the output, or Download to save it as a .txt file.
  5. Need the reverse? The Base64 to PDF tool decodes and previews the result.

Real Example

A 245 KB invoice.pdf produces a Base64 string of roughly 327,000 characters — Base64 output is always about a third larger than the binary file. The Data URI tab wraps the same data as data:application/pdf;base64,JVBERi0x..., ready to paste into an HTML attribute, a JSON field or a test fixture. Switching to the JavaScript or Python tab gives you the exact code that performs this same encoding.

Code Snippets

// Encode a PDF file as Base64 (browser) const buffer = await file.arrayBuffer(); const bytes = new Uint8Array(buffer); let binary = ''; bytes.forEach(b => (binary += String.fromCharCode(b))); const base64 = btoa(binary);

How PDF to Base64 Works

Base64 turns every three bytes of your PDF into four text characters from a 64-character alphabet, which is why the output is about 33% larger than the file. A Data URI simply prefixes that text with data:application/pdf;base64, so a browser or JSON consumer knows what it is holding. Because the encoding is done by your browser reading the file locally, the PDF is never transmitted anywhere — you can safely convert confidential documents like contracts or invoices.

Common Use Cases

  • Embedding a PDF in a JSON payload for an API that only accepts text.
  • Creating a Data URI to inline a small PDF in an HTML prototype.
  • Storing a document in a database text column or a config file.
  • Building test fixtures with real PDF content for a parser.
  • Sending a document through a system that strips binary attachments.

FAQ

How do I convert a PDF file to Base64?
Drag the PDF onto the tool above or choose it from your device. The Base64 appears immediately, and you can copy it or download it as a text file.
What is the difference between the Base64 and Data URI output?
The Base64 tab is the raw encoded text. The Data URI tab adds a data:application/pdf;base64, prefix so the string can be used directly in HTML, CSS or JSON consumers that expect a Data URI.
Why is the Base64 output bigger than my PDF?
Base64 represents every 3 bytes as 4 characters, so the text is always about 33% larger than the original file. That is normal and expected.
Can I put the output straight into a JSON request?
Yes — the plain Base64 output contains no line breaks, so it can be pasted into a JSON string field as-is.
Is my PDF uploaded to a server?
No. The file is read and encoded by your own browser. You can watch the network panel in your developer tools: nothing is sent anywhere.

Related Tools