Skip to content
PDFToolz

PDF to Base64 Converter

Turn a PDF into a Base64 string or data URI, copy it or save it as .txt, with ready HTML, JSON and curl snippets.

Select a PDF file

or drop it anywhere on this page, or paste

Opens in your browser. Nothing is uploaded.

PDF to Base64 Converter, free and private

This PDF to Base64 converter turns a PDF file into a Base64 string you can paste into JSON, HTML, an email or a database field. Choose raw Base64, a data URI that starts with data:application/pdf;base64, or MIME lines of 76 characters. Then copy the result or download it as a .txt file.

The file is read and encoded in your browser, so the PDF is never uploaded. The tool encodes the raw bytes without changing them, so the string decodes back to an identical file.

How to convert a PDF to Base64

  1. 1

    Choose the PDF

    Choose a PDF up to 150 MB or drop it on the page. Encoding starts right away, and the output box shows the first 2,000 characters of the result.

  2. 2

    Pick a Base64 format

    Raw Base64 is one unbroken line. Data URI adds the 28-character data:application/pdf;base64, prefix that browsers need in src and href attributes. MIME splits the text into lines of 76 characters for email.

  3. 3

    Copy the string or a snippet

    Press Copy Base64 to put the whole string on your clipboard. The Snippet tab gives ready code for an HTML embed, an iframe, a download link, a JSON body and a curl request, and Copy snippet copies it with the full string.

  4. 4

    Convert PDF to Base64 and save it

    Press Convert to Base64, then Download .txt. The file name ends in .base64.txt, and the text is plain ASCII that any editor opens.

Why use PDFToolz for this

Chunked encoding for large files

The PDF is encoded 24,576 bytes at a time and the pieces are joined. A 100 MB file encodes without the call stack error that a one-line btoa() call hits on large files.

Exact size readout

Beside the output you see the PDF size, the number of characters and the size of the text. Base64 needs 4 characters for every 3 bytes, so a 1 MB PDF becomes 1,398,104 characters.

Snippets ready to paste

Snippets always use the full string without line breaks, because a line break inside an HTML attribute or a JSON string breaks it. The file name is escaped for HTML and JSON.

Nothing leaves your device

The PDF is read and encoded in this browser tab. No server receives it, and closing the tab clears it from memory.

Why Base64 makes a PDF about 33% larger

Base64 writes binary data with 64 safe characters. Each character carries 6 bits, so 3 bytes of the PDF become 4 characters of text. The ratio is fixed, and compressing the PDF first is the only way to get a shorter string.

Some PDF sizes and their Base64 length:

  • A 100 KB PDF of 102,400 bytes becomes 136,536 characters.
  • A 1 MB PDF of 1,048,576 bytes becomes 1,398,104 characters.
  • A 10 MB PDF becomes 13,981,016 characters.
  • MIME line breaks add 2 characters for every 76, about 2.6% on top.
  • If an API caps request bodies at 10 MB, the PDF itself has to stay under about 7.5 MB. Run larger files through Compress PDF first.

Which Base64 format to choose

The three outputs hold the same data with different wrapping:

  • Raw Base64 suits a JSON field, a database column or an API that asks for the file content as a Base64 string.
  • Data URI goes in the src of an <iframe> or <embed>, or the href of a download link. The prefix tells the browser that the data is a PDF.
  • MIME lines suit a hand-built email or any system that rejects lines longer than 76 characters. The line breaks are CRLF, as RFC 2045 requires.

Embedding a Base64 PDF in a web page

The HTML embed and iframe snippets put the whole PDF inside the page, so it shows without a separate file request. This works well for small files. Chrome and Edge cap URLs at 2 MB, and a data URI counts as a URL, so a PDF over about 1.5 MB will not display this way. The tool shows a warning under the embed, iframe and link snippets when the data URI passes that limit.

Browsers also block opening a data: URL in a new tab from a normal link. The download link snippet adds the download attribute, so a click saves the file instead. The same 2 MB cap applies to these links in Chrome and Edge. For large PDFs, serve the file from a normal URL, or decode the Base64 into a Blob in JavaScript and show it with URL.createObjectURL.

Converting a PDF to Base64 on the command line

Each desktop system has a built-in command that gives raw Base64 like the default output here:

  • On macOS, run base64 -i report.pdf -o report.txt in Terminal.
  • On Linux, run base64 -w 0 report.pdf > report.txt. The -w 0 flag turns off the line break that GNU base64 adds every 76 characters.
  • On Windows, run [Convert]::ToBase64String([IO.File]::ReadAllBytes("C:\docs\report.pdf")) in PowerShell. The certutil -encode command also works, but it adds BEGIN and END CERTIFICATE lines that you have to delete.

Limits

The tool encodes one PDF of up to 150 MB at a time. The Base64 of a larger file comes close to the longest string some browsers can hold. Copying many megabytes to the clipboard can fail on phones, so use Download .txt for big files.

The PDF is not compressed, split or changed in any way. A password protected PDF is encoded as it is, and whoever decodes it still needs the password.

Frequently asked questions

Related tools and guides