In my laravel project I have the following myview.blade.php content:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{{ __('menu.title') }}</title>
</head>
<body>
{{__('content') }}
</body>
But instead of rendering it into a http response, I want to be able to generate a pdf file out of it. Do you know…
Top comments (3)
I used many solutions, including DOMPDF, but on average the output generated by WKHTMKTOPDF is far better than DOMPDF.
WKHTMKTOPDF follow CSS rules more precisely.
Well, wkhtmltopdf is a command line program that accepts an html file as parameter, so you just have to install it and you are ready to go. It has package for Linux and Windows.
To the code
Generate the desired html from your view, like this:
Write the HTML to a temporary file:
Run exec() on wkhtmltopdf:
Download your
$pdf_file
.Be happy.
Used DOMPDF before with some issues with images. I recommend using Browsershot instead as it can handle any images and CSS.
The only drawback is it cannot merge PDF's, so you will have to merge PDF pages in your own PHP code.
github.com/spatie/browsershot
Please, add the tag #help in this post.