Dmytro Vlasenko
Dmytro Vlasenko

Reputation: 19

How to open base64 PDF in Chrome app?

I have a simple Chrome application. There is a base64 string. In it, I store a PDF file and I want to open this PDF file on new window or iframe.

I tried to create an iframe with src="data:application/pdf;base64,..".

After that, I get this error:

Refused to load plugin data from 'data:application/pdf;base64,JVBERi0xLjQKJcOkw7zDtsOfCjIgMCBvYmoKPDwvTGVuZ3R…Q4RUU5MzdDRDQyM0RFNEI4MTkzNDU3MzIzMTM2OQo+PgpzdGFydHhyZWYKMjA0NTQKJSVFT0YK' because it violates the following Content Security Policy directive: "default-src 'self' chrome-extension-resource:". Note that 'object-src' was not explicitly set, so 'default-src' is used as a fallback.

Upvotes: 0

Views: 22674

Answers (2)

Villasweet
Villasweet

Reputation: 21

try loading it as a new tab, then in the browser bar, you can paste this where "xxx" is equivalent to the base 64 code

data:application/pdf;base64,XXXX

Hope this helps too.

Upvotes: 1

Nir Lanka
Nir Lanka

Reputation: 378

As Xan mentioned, try loading it as a new tab.

In a web page, you can do either

window.open('data:application/pdf;base64,DATA', '_blank')

or (to load on same window)

window.location.href="data:application/pdf;base64,DATA"

Hope this helps. :/

Upvotes: 5

Related Questions