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.
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.
Thanks
It’s a build off of this stack overflow issue:
https://stackoverflow.com/questions/46563607/angular-4-image-async-with-bearer-headers
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?
<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?
Is there any legitimate way a base64 string could begin with an '=' sign?
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.