【发布时间】: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