Generate PDF Base64

Asked

Viewed 3,926 times

4

I have an Laravel API that generates a PDF with Snappy dock.

Works perfectly on Chrome linux but in windows that has the newest version of Chrome does not work, Chrome only opens a blank page.

I get base 64 that way:

window.open('data:application/pdf;charset=utf-8;base64,' + res.data.print_64);

1 answer

2

Starting with Chrome version 60, top-frame Urls have been blocked, as follows:

Summary

We intend to block web pages from loading data: Urls in the top frame using tags, window.open, window.Location and similar mechanisms.

Motivation

data: Urls are generally a source of Confusion for users. Because of their unfamiliarity and Ability to Encode arbitrary untrusted content in a URL, they are widely being used in spoofing and phishing Attacks. Another problem is that they can be passed along without a backing page that runs Javascript (e.g. a data URL can be sent via email). For that Reason, we intend to block top-frame navigations to data Urls.

Source: https://productforums.google.com/forum/#! topic/Chrome/k-9y57tme2E

Alternative: Render your PDF in one <object>

var base64 = 'seuBase64';
var novaJanela = window.open("", "PDF", 'dependent=yes,locationbar=no,scrollbars=no,menubar=no,resizable,screenX=50,screenY=50,width=850,height=800');
novaJanela.document.write('<html><body><object width=100% height=100% type="application/pdf" data="data:application/pdf;base64,' + base64 + '"><embed type="application/pdf" src="data:application/pdf;base64,' + base64 + '"></embed></object></body></html>');
novaJanela.window.focus();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.