简体   繁体   中英

How to print an image with DomPDF in laravel?

I am making a pdf, for which I use the library: barryvdh/laravel-dompdf , in the pdf I try to print an image, with which when I open the recently downloaded file, all the data is printed except the image, I clarify this image if it is displayed correctly in my show.blade view , I cannot find a solution for this problem. Below I detail how I am proceeding:

Controller: (fragment of store method and exportPdf method)

    public function store(SaveDocumentRequest $request)
    {
    if ($request->hasFile('photo')) {               

        $file = $request->file('photo');
        $name = time().$file->getClientOriginalName();
        $file->move(public_path().'/images/', $name);   
    }else{
          $name = null; 
    }  
   $document->photo  = $name;
    public function exportPdf()
    {
        $movie = Movies::with('document.creator', 'actors', 'generate_movie', 'document.adequacy', 'document.lenguage')->first();

        $pdf = PDF::loadView('admin.movies.show', compact('movie'));  
       
        return $pdf->download('cine.pdf');
    }

My show.blade file:

<div class="col-md-6">    
        <div class="box box-primary">
            <div class="box-header with-border">
              <h3 class="box-title">Imagen de Portada </h3>
            </div>        
            <div class="box-body box-profile">                                          
                <img class="img-responsive" src="{{ asset('/images/'.$movie->document->photo) }}"  alt="{{ $movie->document->title }}" >
            </div>
        </div>
    </div>  

This way I am accessing the image that if it is displayed correctly in my show.blade file, but it is not displayed in the downloaded pdf.

I clarify I do not receive any type of error and the image is stored in the public folder of the project.

Could you guide me to find the solution?

Its simple just use this I have used same package and added image on pdf like this.

 <img  src="{{asset('foldername/path_to_image')}}">

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