barryvdh / laravel-snappy

Laravel Snappy PDF
MIT License
2.64k stars 292 forks source link

laravel include css files #183

Closed sergiybutenko closed 4 years ago

sergiybutenko commented 7 years ago

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. BTW i'm using LaraDock, maybe this helps. 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
barryvdh commented 7 years ago

Does http://localhost/js/app.js exist? Or do you need to set the app url?

sergiybutenko commented 7 years ago

yes, here: http://joxi.ru/YmEYey8tEqKbm6

ghost commented 7 years ago

Same error with me. any solutions for this?

swash13 commented 7 years ago

i decide to use another files just for pdf export and include css files with absolute path (absolute path is working)

ghost commented 7 years ago

Thank you. I already solved my problem .

On Tue, Apr 25, 2017 at 9:31 PM, swash13 notifications@github.com wrote:

i decide to use another files just for pdf export and include css files with absolute path (absolute path is working)

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/barryvdh/laravel-snappy/issues/183#issuecomment-297030688, or mute the thread https://github.com/notifications/unsubscribe-auth/ARJiHgAgXym9vD7eQM68icLhL0Zaj1KPks5rzfXMgaJpZM4MlZU_ .

barryvdh commented 7 years ago

How?

Harti commented 7 years ago

Was anybody able to resolve this issue?

I've been trying to mess around with the --proxy option but didn't get anything to run due to the laradock setup. I'm not entirely sure which container is responsible for what.

However, when I add 10.0.75.1 dockerhost to my Windows hostfile and browse to http://dockerhost instead of http://localhost, the PDF will load just fine.

litan1106 commented 7 years ago

Same issue on Docker for Mac (docker v17.09 ce). I solved it by using docker.for.mac.localhost instead localhost

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Any issues with PDF rendering itself that are not directly related to this package, should be reported on https://github.com/KnpLabs/snappy instead. When having doubts, please try to reproduce the issue with just snappy. If you believe this is an actual issue with the latest version of laravel-snappy, please reply to this issue so we can investigate further. Thank you for your contribution! Apologies for any delayed response on our side.

kkallasm commented 1 year ago

Problem still exists. Did someone found the solution?