Marcin
Marcin

Reputation: 83

Laravel - barryvdh pdf - how include external css file into html view

I have a problem with creating pdf file. I include css3 file into head section in view, but it's doesn't work.
Included file is twitter bootstrap css and main css of application theme.

...
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <link type="text/css" media="all" rel="stylesheet" href="packages/bootstrap/css/bootstrap.min.css">
    <link type="text/css" media="all" rel="stylesheet" href="css/dashboard/style.min.css">
</head>
...

Have an idea?

Upvotes: 3

Views: 11758

Answers (3)

entoniperez
entoniperez

Reputation: 564

I solve this problem by typing the public_path in href attribute, following instruccions from https://github.com/barryvdh/laravel-dompdf/issues/121#issuecomment-358245406:

<link href="{{ public_path('css/pdf.css') }}" rel="stylesheet">

NOTE: I'm using a local virtual server. I hope this works for you.

Upvotes: 4

david.juntak
david.juntak

Reputation: 61

I solve this problem by using external CSS's full path. This one worked on my linux ubuntu server :

<link rel="stylesheet" href="/var/www/mysite/public/css/main.css" media="all" />

You also can solve not loaded image problem by using this solution.

Upvotes: 0

Barryvdh
Barryvdh

Reputation: 6579

Can you try to use a full path? (eg. use the asset() helper)

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <link type="text/css" media="all" rel="stylesheet" href="{{ asset('packages/bootstrap/css/bootstrap.min.css') }}">
    <link type="text/css" media="all" rel="stylesheet" href="{{ asset('css/dashboard/style.min.css') }}">
</head>

I'm assuming you are using https://github.com/barryvdh/laravel-dompdf ? An alternative is using wkhtmltopdf, which is possible with the same interface etc: https://github.com/barryvdh/laravel-snappy (but requires to install wkhtmltopdf)

Upvotes: 1

Related Questions