Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

CooL's avatar
Level 2

laravel-snappy css files

How to include external css files with laravel to make it work ? It's not converting because of error. When i try to convert simple html without including any css files - it works perfect. I tried both url() and asset() helpers. Also i tried absolute path like: {{ public_path('css/app.css') }} and it's not only didn't generate pdf, but also css files was not load on the page and all my styling disappears. Here my view:

    @extends('layouts.app')

@section('title')
    TEST
@endsection

@section('content')
<div class="container">
    <div class="row">
        <div class="col-md-12 welcome-screen">
            <h1 class="TEST-welcome-logo"><img src="{{ url('/img/home-logo.jpg') }}"></h1>
        </div>
    </div>
</div>
@endsection

It's layouts/app.php:

<!-- Styles -->
    <link href="{{ url('bootstrap/css/bootstrap.min.css') }}" rel="stylesheet">
    <link href="{{ url('css/datatables.min.css') }}" rel="stylesheet">
    <link href="{{ url('css/selectize.bootstrap3.css') }}" rel="stylesheet">
    <link href="{{ url('css/jquery-ui.min.css') }}" rel="stylesheet">
    <link href="{{ url('css/bootstrap-datetimepicker.min.css') }}" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="{{ url('css/sweetalert.css') }}">
    <link href="{{ url('css/app.css') }}" rel="stylesheet">

Here's output error in laravel.log file:

[2017-03-22 15:18:19] local.ERROR: RuntimeException: The exit status code '1' says something went wrong:
stderr: "Loading pages (1/6)
[>                                                           ] 0%
[======>                                                     ] 10%
[=======>                                                    ] 12%
Warning: Failed to load file:///uploads/7abde879392e5298903cb5946ba58aef271e28c158e7140ce183ed34574a9c44.jpg (ignore)
Warning: Failed to load http://localhost/css/sweetalert.css (ignore)
Warning: Failed to load http://localhost/css/app.css (ignore)
Warning: Failed to load http://localhost/js/moment.js (ignore)
Warning: Failed to load http://localhost/js/bootstrap-wysiwyg.js (ignore)
Warning: Failed to load http://localhost/js/app.js (ignore)
Warning: Failed to load http://localhost/img/info-book.png (ignore)
Warning: Failed to load http://localhost/img/home-logo.jpg (ignore)
Warning: Failed to load http://localhost/img/ditaso-footer.png (ignore)
[=======>                                                    ] 13%
[============================================================] 100%
Counting pages (2/6)                                               
[============================================================] Object 1 of 1
Resolving links (4/6)                                                       
[============================================================] Object 1 of 1
Loading headers and footers (5/6)                                           
Printing pages (6/6)
[>                                                           ] Preparing
[==============================>                             ] Page 1 of 2
[============================================================] Page 2 of 2
Done                                                                      
Exit with code 1 due to network error: ConnectionRefusedError
"
stdout: ""
command: /var/www/laravel/vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64 --lowquality --print-media-type --viewport-size '1024x1500' '/tmp/knp_snappy58d295bb4634b4.16726344.html' '/tmp/knp_snappy58d295bb463d41.83569796.pdf'. in /var/www/laravel/vendor/knplabs/knp-snappy/src/Knp/Snappy/AbstractGenerator.php:336

0 likes
3 replies
vipin93's avatar

use like this

<link rel="stylesheet" type="text/css" href="{{asset('/css/bootstrap.min.css')}}">

in your print blade file

CooL's avatar
Level 2

tried, same result. Btw i'm using LaraDock, maybe this will help.

vipin93's avatar

for print don't extend your layouts use different view and use only asset which required use assets also for "image " because whtml looking http/localhost/..... here u can see

Warning: Failed to load file:///uploads/7abde879392e5298903cb5946ba58aef271e28c158e7140ce183ed34574a9c44.jpg (ignore)
Warning: Failed to load http://localhost/css/sweetalert.css (ignore)
Warning: Failed to load http://localhost/css/app.css (ignore)
Warning: Failed to load http://localhost/js/moment.js (ignore)
Warning: Failed to load http://localhost/js/bootstrap-wysiwyg.js (ignore)
Warning: Failed to load http://localhost/js/app.js (ignore)
Warning: Failed to load http://localhost/img/info-book.png (ignore)
Warning: Failed to load http://localhost/img/home-logo.jpg (ignore)
Warning: Failed to load http://localhost/img/ditaso-footer.png (ignore)

Please or to participate in this conversation.