简体   繁体   中英

laravel 7 download pdf with barryvdh / laravel-dompdf

I'm using https://github.com/barryvdh/laravel-dompdf to download pdf but it's adding border around the content and it's ignoring the html tags. It's simply showing the html tags on pdf file.

This is my controller:

public function download(Request $request, $id)
{
    // dd($request);
     // $pdf = PdfToWord::find($id);
    $ptw = Ebook::where('id',$id)->orderBy('id', 'desc')->first();
    // $idd = $ptw->id;
    $ebook = EBookChapter::where('ebook_id',$id)->get();
     // return view('app.ebutifier.book')->with('pdf',$pdf);
    $params = ['ptw' => $ptw, 'ebook' => $ebook];

    view()->share($params);

        $pddf = PDF::loadView('app.ebook.book',$params);

        return $pddf->setPaper('a4', 'portrait')->download('myebook.pdf');
    // }
}

This is the blade file:

<!-- Row -->
            <div class="row">
                <div class="col-xl-12">
                    <section class="hk-sec-wrapper">
                        <div class="page">
                            <div class="page1 text-center">
                                <div class="text-middle" style="background-image: url('{{ asset('../storage/app/public/ebook/'.$ptw->image) }}')">
                                    <h2 style="text-align: center;"> {{ $ptw->title }}</h2>
                                
                                </div>
                                 {{-- <img src="{{ asset('../storage/app/public/ebook/'.$ptw->image) }}" alt="{{ $ptw->title ?? ''}}" style="height: auto; width:100%;"> --}}
                            </div>
                            <div class="page2" class="" >
                                @foreach($ebook as $ebooks)
                                    <h5 style="text-align: center;">{{$ebooks['chapter_name'] }}</h5>
                                    <p>{!! $ebooks['body'] !!}</p>
                                    <br>
                                @endforeach 

                            </div>
                        </div>
                    </section>
                </div>  
            </div>
            <!-- /Row -->

I have removed all the border style from html but still it adds the border. Here's the link to image

https://snipboard.io/C3dq5a.jpg

In my experience barryvdh/laravel-dompdf is very picky when it comes to the html & css used. I would advise rolling the document back to a very basic form and warp it with full HTML tags

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    ...
</head>
<body>
   you code here
</body>
</html>

i can also see in your blade file that you are trying to add pictures, in case you are having problems check out this: Laravel dompdf error "Image not found or type unknown"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM