【问题标题】:Laravel dom pdf image issueLaravel dompdf图像问题
【发布时间】:2016-08-19 07:54:32
【问题描述】:

我在 laravel 中使用 dompdf 创建发票。它对我来说很好,直到我在其中使用图像。

管理控制器

 public function generateInvoice(Request $request)
{
    $user = Auth::user();
    $pdf        = PDF::loadView('pdf.invoice', $user);
    return $pdf->download('invoice.pdf');
}

在包含发票模板的发票查看页面中...

<style>
.block{
	display: block;
}
.minifont12{
	font-size: 12px;
}
.minifont10{
	font-size: 10px;
}
.col-md-45{
	width: 45%;
	display: inline-block;
}
.col-md-30{
	width: 30%;
	display: inline-block;
}
.col-md-25{
	width: 24%;
	display: inline-block;
}
.bluecolor{
	background-color: #C5C5EC;
}
.midtop{
	margin-top: 50px;
}
</style>
<div class="header" style="position:relative; top:10; width:100%; ">
<img src="http://localhost:8000/img/minilogo.jpg">
<div style="text-align:center; margin-top:-20px;">Retail Invoice/Bill</div>
<div style="text-align:right">Invoice No. #BTR_PB_000052</div>
</div>
<div class="content">
	<div class="minifont12 block" style="margin-top:20px;">
	<strong>Sold By:</strong> SRM Smart Solutions Pvt. Ltd.<br>
		<span class="minifont10">
			Building No. 29, Third Floor, Central Market, West Punjabi Bagh, Delhi-110026
		</span>
	</div>
	<hr>
	<div class="col-md-45">
		Order Id : BT121178273<br>
		Order Date : 24-05-2016<br>
		Invoice Date : 25-05-2016<br>
		CIN No. : U72300DL2015PTC281652
	</div>
	<div class="col-md-30">
		Avinash<br>
		H.No 30-45-5/26, Chandigari colony east, rohit cottage lane, opp. krupa comlex lane, r.k.puram post, 500 056, hdy.<br>
		Hyderabad, telangana - 500056<br>
		8099473211
	</div>
	<div class="col-md-25">
		<span class="midtop bluecolor">
			*Keep this invoice for return and refund purposes
		</span>
	</div>
</div>

但是当我运行代码时...它会显示错误消息 超过 60 秒的最大执行时间

请告诉我这背后的问题..

【问题讨论】:

  • 你是否完成了php artisan vendor:publish,然后进入你的config/目录,然后编辑dompdf.php,然后设置show_warnings = true?应该给你更好的错误报告。另外,您可以尝试将图像作为 base 64 编码图像传递给 pdf 视图,然后在 PDF 中使用该图像的内容吗?设置您的源 $src = public_path().'/img/minilogo.jpg';,然后创建要传递给视图的 $image 变量:$image = 'data: '.mime_content_type($src).';base64,'.base64_encode(file_get_contents($src)); 现在设置 &lt;img src="'. $image .'"/&gt;
  • 如果您使用不同的图像(例如来自公共服务器),您还有问题吗?

标签: laravel dompdf


【解决方案1】:

我在使用非常大的图像时遇到了同样的问题。我通过在开始创建 pdf 之前添加以下行来更改最大执行时间来解决这个问题:ini_set('max_execution_time', 120);。如果你愿意,你也可以在你的 php.ini 文件中改变它,只要确保你知道你在做什么,因为这个设置适用于在你的 web 服务器上执行的所有脚本。在更改 php.ini 文件后,您还必须重新启动 Web 服务器。

讨论了其他一些解决此问题的选项here

【讨论】:

    【解决方案2】:

    您可以使用此代码:

    <img src="{{ public_path("images/a.png") }}">
    

    或者可以:

    <div style="background: url({{ public_path("images/a.png"}})">text</div>
    

    【讨论】:

      猜你喜欢
      • 2012-11-30
      • 2015-10-22
      • 2018-08-05
      • 2021-01-18
      • 1970-01-01
      • 1970-01-01
      • 2014-12-24
      • 2021-12-07
      • 2021-10-13
      相关资源
      最近更新 更多