Generate Base64 PDF

3

I have a laravel API that generates a PDF with laravel snappy.

It works perfectly in chrome linux but on windows that has the newer version of chrome does not work, chrome only opens a blank page.

I get base 64 like this:

window.open('data:application/pdf;charset=utf-8;base64,' + res.data.print_64);
    
asked by anonymous 30.08.2017 / 23:50

1 answer

1

As of Chrome version 60, top-frame URLs have been blocked, as follows:

  

Summary

     

     

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 used in spoofing and phishing attacks. Another problem is that they can be passed along without the backing page that runs JavaScript (e.g. the URL data can be sent via email). For that reason, we intend to block top-frame navigations to data URLs.

Source: link

Alternative: Render your PDF to a <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();
    
24.10.2017 / 17:13