barryvdh / laravel-dompdf

A DOMPDF Wrapper for Laravel
MIT License
6.79k stars 978 forks source link

How can I add external css to generate PDF using view file #121

Closed avptechnocrats closed 4 years ago

avptechnocrats commented 9 years ago

How can I add external css to generate PDF using view file? Can you please help me in this?

hiddeco commented 9 years ago

Add the following line to the head part of your blade file to include the external CSS.

<link rel="stylesheet" href="{{ asset('/path/to/your/pdf.css') }}" media="all" />
iamraffe commented 9 years ago

This is not working for me. No CSS styles are being loaded

tejasrsuthar commented 8 years ago

Same here :(

davidjuntak commented 8 years ago

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.

barryvdh commented 8 years ago

Are you using actual servers? Or CLI or something? I think absolute urls should work for apache/nginx

davidjuntak commented 8 years ago

I am using actual production server (Ubuntu 12.04) and it works.

Here take a look about this topic on http://stackoverflow.com/questions/25558449/dompdf-image-not-readable-or-empty

venkateshcontus commented 7 years ago

I have tried the below code $pdf = app()->make('dompdf.wrapper'); $pdf->loadHTML('

Test

'); return $pdf->stream(); Blank pdf is generated . But it's work in my local system.

hekmatinasser commented 6 years ago

I solve this problem by using external CSS's full path. This one worked on my linux ubuntu server : <link href="{{ public_path('css/bootstrap.min.css') }}" rel="stylesheet" type="text/css" /> and work on image.

AbdullahValley commented 6 years ago

any solution for windows user ??

its not woking - loading and loading

himalayaahuja commented 6 years ago

I am using external css with full url paths , but i am getting an error , while generating pdf i think it is not able to parse / read css classes or selectors.. here's the error i am getting : laravel_dompdf_issue

heidilux commented 6 years ago

@himalayaahuja You're just missing the /fonts directory that you need to create in your storage directory

StrikeAgainst commented 6 years ago

Will there be a way to load this in via Laravel helper functions any time soon? Working with fixed URLs is highly unreliable...

vince83110 commented 6 years ago

It works for me on Windows :

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

adysxp commented 5 years ago

fix permission +750 all folder css, work fine:

<link rel="stylesheet" href="{{ URL::asset('css/site.css') }}" type="text/css" />
<link rel="stylesheet" href="{{ URL::asset('bootstrap/css/bootstrap.min.css') }}" type="text/css" />
zorenkonte commented 5 years ago

It works for me on Windows :

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

Im using windows and it works. Thanks!

dxm99 commented 4 years ago

I was in hurry so i used Occam's razor. I created another blade template, pdf-css, with only one tag:

and in my tempates i added

@include('pdf-css')

It's prolly not the best solution but it is a solution that works without hussle

stipsuarez commented 4 years ago

dompdf have some probles with some styles, for example display:flex. I have to creete a view.blade.php :

Fabri Hogar

Órden de Pedido

{{$sellerorder->id}}

NIT: {{$company->nit}}

Dirección: {{$company->address}} PISO 3 Tel: {{explode(',',$company->telephone)[0]}} {{$company->city->name}}. D.C - Colombia

Cliente:{{$sellerorder->customer->name_customer}}

CC/Nit: {{$sellerorder->customer->cc}}

Dirección: {{$sellerorder->customer->address}}, {{$sellerorder->customer->city->name}}, {{$sellerorder->customer->department->name}}

Teléfono: {{$sellerorder->customer->telephone}}

Fecha de creada: {{date('d-m-Y', strtotime(str_replace('-', '/', $sellerorder->created_date)))}}

Vendedor: {{$sellerorder->seller->user->name}}

Condición de Pago: {{$sellerorder->payment_type}}

Número de Seguimiento: {{$sellerorder->tracking_number}}

Fecha de envío: @if($sellerorder->shipping_date) {{date('Y-m-d', strtotime(str_replace('-', '/', $sellerorder->shipping_date)))}} @endif

    </table>

and add some styles: .left {

        text-align: left;
        margin: 30px;
    }

    .rigtht {
        text-align: right;
        margin: 30px;

    }

    .center {
        text-align: center;
        align-items: center;
        align-content: center;
        width: 100%;
    }

    .center-img {
        text-align: center;
        align-items: center;
        align-content: center;
    }

    html {
        margin: 10px;
    }

    body {
        font-family: "Times New Roman", serif;
        margin: 45mm 8mm 2mm 8mm;
    }

    .rounded-pill {
        border: solid 1px #86895D;
        border-radius: 10px;
        background-color: #86895D;
        color: #fff !important;
        margin: 5px;
    }
</style>
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/dompdf/dompdf instead. When having doubts, please try to reproduce the issue with just dompdf. If you believe this is an actual issue with the latest version of laravel-dompdf, please reply to this issue so we can investigate further. Thank you for your contribution! Apologies for any delayed response on our side.