简体   繁体   中英

attach img on pdf download using laravel dompdf server provider

I want attach an image on my pdf when pdf is downloaded, I am using dompdf service provider in laravel 8 version, I am using public path method but the image still not attaching the pdf file.

 public function invoicepdf($productid, $orderId)
      {
            $orderHistory = Order::where('order_id',$orderId)->orderBy('id', 'DESC')->first();
            $orderProductDetails[]=json_decode($orderHistory->product_details,true);
            foreach($orderProductDetails as $orderdata)
            {  
              foreach($orderdata as $orderDetail )
              {   
                  if($orderDetail['product_id']== $productid)
                  { 
                    $productDetails = $orderDetail; 
                    $marchantdetails = UserData::where('user_id',$orderDetail['marchent_id'])->first();
                  }
              }
            }
          $pdf = PDF::loadView('front_end.invoice',compact('orderHistory','productDetails','marchantdetails'))->setOptions(['defaultFont' => 'sans-serif']);
          // download PDF file with download method
          return $pdf->download('pdf_file.pdf');
      } ```

this is my pdf download function or method 

     <div style="text-align: center;">
        <img src="{{ public_path('public/image.png') }}" style="width: 100px; height: 100px">
    </div>
   <p>ut aliquip ex ea commodoconsequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
    cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidata.</p>

this is my pdf blade file code 

when I am using this pubic_path function pdf is downloading but the image is not attached with pdf file, please help me with this.


use this code at your blade file where $data

echo '<img src="data:image/jpg;base64,' . $data->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