【问题标题】:attach img on pdf download using laravel dompdf server provider使用 laravel dompdf 服务器提供程序在 pdf 下载上附加 img
【发布时间】:2022-01-21 20:43:45
【问题描述】:

我想在下载 pdf 时在我的 pdf 上附加一个图像,我在 laravel 8 版本中使用 dompdf 服务提供商,我使用公共路径方法但图像仍然没有附加 pdf 文件。

 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.


【问题讨论】:

  • 您是否尝试过使用绝对/相对路径,如果不起作用,请尝试使用 base64 对图像进行编码
  • 如何使用绝对/相对路径,对服务器也有帮助?
  • 相对路径也可以在服务器上使用。对于赦免路径,您可能需要进行一些更改。

标签: php image download laravel-8 dompdf


【解决方案1】:

使用 此代码在您的刀片文件中,其中 $data

echo '<img src="data:image/jpg;base64,' . $data->image.'">';

【讨论】:

    猜你喜欢
    • 2014-10-15
    • 2023-04-09
    • 2016-08-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-10
    • 1970-01-01
    • 2018-12-23
    相关资源
    最近更新 更多