2

My controller

$pdf = PDF::loadView('pdf', $data);
$pdf->setPaper('a6', 'landscape')->setWarnings(false);
return $pdf->stream();

My function in VueJS

preview() {
        axios.post('/orders/preview')
        .then(function (response) {
          window.open("data:application/pdf," + encodeURI(response.data)); 
        })
        .catch(function (error) {
          // Error callback
        });
      }

However I get this string in return

%PDF-1.3
1 0 obj
<< /Type /Catalog
/Outlines 2 0 R
/Pages 3 0 R >>
endobj
2 0 obj
<< /Type /Outlines /Count 0 >>
endobj
3 0 obj
<< /Type /Pages
/Kids [6 0 R
10 0 R
13 0 R
18 0 R
21 0 R
...

If I try to open that with window.open it just opens an empty page... Should domPDF not open a new tab automatically with ->stream()? Or how can I open the pdf with the given string in JS?

Mango D
  • 501
  • 3
  • 11
  • 28
  • The trouble you're running into doesn't really have anything to do with Dompdf. You've requested content from the server and it was returned. What you need is to figure out how to handle the returned data. – BrianS Aug 08 '17 at 22:09

1 Answers1

0

you could maybe just return URL for that PDF and then redirect user to new tab where he can see/download that PDF.

Download and open pdf file using Ajax

remmargorp
  • 31
  • 1
  • 4