0

I am trying to create PDF from a Blade. My View has example same static Html as showing in this plunker link

My code is simple...using barryvdh/laravel-dompdf package...I am writing below code in controller action method

$pdf = \PDF::loadView('ViewPage', ["Data" => 123]);
return $pdf->download('sample.pdf');

Now, the problem is when i view it in html page...it works perfectly and we may check the correct expected output here: https://plnkr.co/edit/an7JsFSkNt52oKi0Oupg?p=preview ...but when I run above code to put the exact same html into PDF...it shows something like this

Am I missing anything?

enter image description here

Marcin Nabiałek
  • 109,655
  • 42
  • 258
  • 291
Pankaj
  • 9,749
  • 32
  • 139
  • 283
  • 1
    The developer of that package has stated he believes WKHTMLTOPDF is superior to DOMPDF. He created a package called Snappy to utilize that very thing. https://github.com/barryvdh/laravel-snappy – Mark Mar 06 '17 at 19:56

1 Answers1

1

Styling PDF is often tricky. You should inline CSS code into your HTML/Blade view and it's quite possible you will need to modify HTML code to make it work in PDF. DomPDF doesn't support everything that is supported when displaying HTML page.

Marcin Nabiałek
  • 109,655
  • 42
  • 258
  • 291
  • Still same, I have now placed the style.css contents directly inside the blade – Pankaj Mar 06 '17 at 19:52
  • @Helper This is only example what should be done, you are using divs and floats and they might also not work as expected using DomPDF so you should start from smaller piece of code to make it work and later add next parts to achieve complete solution – Marcin Nabiałek Mar 06 '17 at 19:54