How to display base64 encoded pdf?

Asked
Active3 hr before
Viewed126 times

6 Answers

display
90%

for those who still can't do it, i found this in someone else answer, but i don't remember who...

var objbuilder = '';
objbuilder += ('<object width="100%" height="100%" data="data:application/pdf;base64,');
objbuilder += (myBase64string);
objbuilder += ('" type="application/pdf" class="internal">');
   objbuilder += ('<embed src="data:application/pdf;base64,');
objbuilder += (myBase64string);
objbuilder += ('" type="application/pdf" />');
   objbuilder += ('</object>');

var win = window.open("#","_blank");
var title = "my tab title";
win.document.write('<html>
<title>'+ title +'</title>

<body style="margin-top: 
0px; margin-left: 0px; margin-right: 0px; margin-bottom: 0px;">');
   win.document.write(objbuilder);
   win.document.write('</body>

</html>');
layer = jQuery(win.document);
load more v
88%

Link to PDF file (or attach file here):,Web browser and its version: Chrome,@capegreg there is no such thing as a "binary PDF". If you want to display base64 encoded string you need to decode it yourself, since only few browsers can decode it. The base64 encoding and decoding is very inefficient operation (for servers and client) -- we don't believe supporting it will be beneficial for PDF.js.,This is actually the reason, I want to use pdf.js. To display inlined pdf data....

0
72%

I have a base64 encoded pdf content and want to view it using sap.m.PDFViwer. Since PDFViewer only accepts URI as source to display pdf:,line 269: PDFViewer try validate the source url,The PDFViewer loads my pdf as below:,However when I use this blob url as source of my PDFViewer, my pdf can’t be loaded at all however my blob url is accessible.

So I should first create a blob url or a data url for my pdf content.

var base64EncodedPDF = "JVBERi0xLjcNCiW..."; // the encoded string
var decodedPdfContent = atob(base64EncodedPDF);
var byteArray = new Uint8Array(decodedPdfContent.length)
for (var i = 0; i < decodedPdfContent.length; i++) {
   byteArray[i] = decodedPdfContent.charCodeAt(i);
}
var blob = new Blob([byteArray.buffer], {
   type: 'application/pdf'
});
var _pdfurl = URL.createObjectURL(blob);

what I do is as below:

if (!this._PDFViewer) {
   this._PDFViewer = new sap.m.PDFViewer({
      width: "auto",
      source: _pdfurl // my blob url
   });
   jQuery.sap.addUrlWhitelist("blob"); // register blob url as whitelist
}
this._PDFViewer.downloadPDF = function() {
   File.save(
      byteArray.buffer,
      "Hello_UI5",
      "pdf",
      "application/pdf"
   );
};
this._PDFViewer.open();

The method addUrlWhitelist has four parameters.

jQuery.sap.addUrlWhitelist(protocol, host, port, path);
load more v
65%

I’ve faced the same issue with IE: it’s impossible to display a pdf with a base64 string., to display base64 encoded pdf It should work with Chrome you can use<iframe src="data:base64..."><object data="data:base64...">I've faced the same issue with IE: it's impossible to display a pdf with a base64 string.I had to generate temporary files on the server to display them with IE he only display existing file by using a path. , to display base64 encoded pdf It should work with Chrome you can use<iframe src="data:base64..."><object data="data:base64...">I've faced the same issue with IE: it's impossible to display a pdf with a base64 string.I had to generate temporary files on the server to display them with IE he only display existing file by using a path., how to display base64 encoded pdf ? to display base64 encoded pdf It should work with Chrome you can use<iframe src="data:base64..."><object data="data:base64...">I've faced the same issue with IE: it's impossible to display a pdf with a base64 string.I had to generate temporary files on the server to display them with IE he only display existing file by using a path.

var objbuilder = '';
objbuilder += ('<object width="100%" height="100%" data="data:application/pdf;base64,');
objbuilder += (myBase64string);
objbuilder += ('" type="application/pdf" class="internal">');
   objbuilder += ('<embed src="data:application/pdf;base64,');
objbuilder += (myBase64string);
objbuilder += ('" type="application/pdf" />');
   objbuilder += ('</object>');

var win = window.open("#","_blank");
var title = "my tab title";
win.document.write('<html>
<title>'+ title +'</title>

<body style="margin-top: 
0px; margin-left: 0px; margin-right: 0px; margin-bottom: 0px;">');
   win.document.write(objbuilder);
   win.document.write('</body>

</html>');
layer = jQuery(win.document);
75%

Jason, 31 october 2019 at 16:53 # While I got error 500 several times trying to convert a 64 encoded PDF back to PDF. I did finally get it to go through and validate. Thank you, great tool. reply , Administrator, 8 october 2019 at 14:00 #↑ Hello! Please check this example Convert Base64 to PDF in PHP. reply , charan, 26 november 2019 at 06:04 # Is it possible to convert base64 pdf type string to text file???????Please help me in this.Thank YouCharan reply , Administrator, 8 october 2019 at 13:34 #↑ Hello Simon! Please check this example: Convert Base64 to PDF in Python. reply

file_put_contents()
load more v
40%

I have to display base64 pdf in new tab. I am using below code,I've faces same issue with IE: it's impossible to display a pdf with a base64 string.,I had to generate temporary files on the server for display them with IE he only display existing file by using a path. ,this way we open the pdf in a new tab.

I have to display base64 pdf in new tab. I am using below code

 var windo = window.open("", "");
 var objbuilder = '';
 objbuilder += ('<embed width='100%' height='100%' src="data:application/pdf;base64,');
 objbuilder += (fileData);
 objbuilder += ('" type="application/pdf" />');
 windo.document.write(objbuilder);
load more v

Other "display-undefined" queries related to "How to display base64 encoded pdf?"