A virtual teacher who reveals to you the great secrets of Base64

PDF to Base64

Convert PDF to Base64 online and use the result string as data URI, HTML object, and others. Sometimes you have to send or output a PDF file within a text document (for example, HTML, JSON, XML), but you cannot do this because binary characters will damage the syntax of the text document. To prevent this, for example, you can encode PDF file to Base64 and embed it using the data URI. Please note that the PDF to Base64 encoder accepts any files types with a size of up to 50 MB. If you are looking for the reverse process, check Base64 to PDF.


How to convert PDF to Base64 online

  1. Choose the source of PDF file from the “Datatype” field.
  2. Paste the URL or select a PDF file from your computer.
  3. If necessary, select the desired output format.
  4. Press the “Encode PDF to Base64” button.
  5. Download or copy the result from the “Base64” field.

About PDF

  • Name: Portable Document Format
  • Developer: Adobe Inc.
  • MIME types: application/pdf, application/x-pdf, application/x-bzpdf, application/x-gzpdf
  • File Extensions: .pdf
  • Uniform Type Identifier: com.adobe.pdf

Output formats

The PDF to Base64 converter generates ready-made examples, depending on the selected output format. It automatically detects the content type of the uploaded PDF file, so that you simply copy the complete result.

If you do not know what output format you need, check the following examples to see how will look the result of the same Base64-encoded PDF file formatted in each of the available formats (as an example Base64 string I use first 64 bytes of a PDF file):

Plain text:
JVBERi0xLjUKJYCBgoMKMSAwIG9iago8PC9GaWx0ZXIvRmxhdGVEZWNvZGUvRmlyc3QgMTQxL04gMjAvTGVuZ3==
Data URI:
data:application/pdf;base64,JVBERi0xLjUKJYCBgoMKMSAwIG9iago8PC9GaWx0ZXIvRmxhdGVEZWNvZGUvRmlyc3QgMTQxL04gMjAvTGVuZ3==
HTML Embed:
<embed type="application/pdf" src="data:application/pdf;base64,JVBERi0xLjUKJYCBgoMKMSAwIG9iago8PC9GaWx0ZXIvRmxhdGVEZWNvZGUvRmlyc3QgMTQxL04gMjAvTGVuZ3==" />
HTML Hyperlink:
<a href="data:application/pdf;base64,JVBERi0xLjUKJYCBgoMKMSAwIG9iago8PC9GaWx0ZXIvRmxhdGVEZWNvZGUvRmlyc3QgMTQxL04gMjAvTGVuZ3=="></a>
HTML Object:
<object type="application/pdf" data="data:application/pdf;base64,JVBERi0xLjUKJYCBgoMKMSAwIG9iago8PC9GaWx0ZXIvRmxhdGVEZWNvZGUvRmlyc3QgMTQxL04gMjAvTGVuZ3=="></object>
JavaScript Popup:
window.onclick = function () {
  this.open("data:application/pdf;base64,JVBERi0xLjUKJYCBgoMKMSAwIG9iago8PC9GaWx0ZXIvRmxhdGVEZWNvZGUvRmlyc3QgMTQxL04gMjAvTGVuZ3==");
};
JSON:
{
  "file": {
    "mime": "application/pdf",
    "data": "JVBERi0xLjUKJYCBgoMKMSAwIG9iago8PC9GaWx0ZXIvRmxhdGVEZWNvZGUvRmlyc3QgMTQxL04gMjAvTGVuZ3=="
  }
}
XML:
<?xml version="1.0" encoding="UTF-8"?>
<root>
  <file mime="application/pdf">JVBERi0xLjUKJYCBgoMKMSAwIG9iago8PC9GaWx0ZXIvRmxhdGVEZWNvZGUvRmlyc3QgMTQxL04gMjAvTGVuZ3==</file>
</root>

If I missed an important output format for Base64-encoded PDF files, please let me know — I would love to implement it.

Comments (20)

I hope you enjoy this discussion. In any case, I ask you to join it.

  • Chad,
    I used this because some Angular components do not like waiting around and will error out. I made a pipe to put a blank pdf while the one requested is downloaded. This helps with a lot of issues

    Thanks
    • Administrator,
      Hey! Thanks for sharing. By the way, I do not know any details about your app, but if possible, instead of a blank PDF consider to embed first page of your real PDF file.
      • Chad,
        It’s an Angular app where I use the blank page as temporary page while the PDF loads from the server. This is so that the app doesn’t error out when waiting for the real content to load. I don’t have any page cached or separated so only serving the first page wouldn’t work.

        It’s a build off of this stack overflow issue:

        https://stackoverflow.com/questions/46563607/angular-4-image-async-with-bearer-headers
        • Administrator,
          Thanks for the explanation. I have not encountered such tasks, but at first glance it seems to be a nice solution.
  • Robin,
    Thanks for the explanation. It's helpful.
  • Sergio,
    thanks for the tool! works fine
  • HardikMehta,
    Sir, I want to know that what is the largest size of PDF can converted into base64 , or if you have any supporting article blog anything to help me with that.
  • Sadhana,
    Hello,

    I am looking for a way to convert a pdf file to base64 in Javascript using FileReader.
    I have the path of the pdf file, but not able to convert to base64. Can you provide some guidance?
  • Matt,
    Is it possible to specify the default page to show? By default, page 1 is shown... can I specify page 2?

        <html>
        <head>
        </head>
        <body>

        <embed type="application/pdf" src="data:application/pdf;base64,[INSERT BASE64 DATE HERE]" page='2'/>
        <div>
        </div>
        </body>
        </html>

    Something like that?
  • sampada_,
    Doesn't work for files with file size>20 MB tried several times but it gives out of memory issue. is there any alternate way to encode such files to byte array Base64.????
    • LuizZamboni,
      Hi, I have the same doubt, how did you manage to solve this problem?
  • Usman,
    Hey! This is a really cool app! Can you share how exactly you did that? Or what the algorithm is behind this conversion??
  • Fernando,
    Excellent! This was help me. Thanks!
  • Bill,
    Hey there! huge fan, your tools have saved me so much time! I have a question, I have a decoder breaking randomly and while trying to troubleshoot it I found I could break it every time with a base64 string with a leading '=' sign.

    Is there any legitimate way a base64 string could begin with an '=' sign?
    • Administrator,
      Hi! As far I know, ASCII Armor is the only standardized way when you have to prepend a '=' sign to the Bas64 string (although, it should be on the second line after the main string).

      Bu the way, some developers use such a character (or other characters) to delimit multiple Base64 strings or different values.

      Anyway, I think you should try the Base64 Normalization Tool and read its hints carefully.
  • nqhXncMU,
    0'XOR(if(now()=sysdate(),sleep(15),0))XOR'Z
  • nqhXncMU,
    -1); waitfor delay '0:0:15' --
  • nqhXncMU,
    if(now()=sysdate(),sleep(15),0)
  • nqhXncMU,
    beVLO34T' OR 12=(SELECT 12 FROM PG_SLEEP(15))--
  • esrefatak,
    Awesome web page. Thanks!
Add new comment

If you have any questions, remarks, need help, or just like this page, please feel free to let me know by leaving a comment using the form bellow.
I will be happy to read every comment and, if necessary, I will do my best to respond as quickly as possible. Of course, spammers are welcome only as readers.