我正在使用berryvdh/dompdf
生成PDF,并将其作为电子邮件附件发送:
$pdf = PDF::loadView($view, compact('******'));
$pdf->setOptions(['dpi' => 300 ]);
$output = $pdf->save('pdf/' . $name_pr);
在电子邮件功能中:
$message->attach($file, [
'as' => $reference.'.pdf',
'mime' => 'application/pdf',
]);
在我的pdf视图中:
<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="content-type">
<style type="text/css">
body{position: relative;}
.pa{
position: absolute;
top: 0;
left: 0;
z-index: 2;
font-family:'Times New Roman';
padding: 0 8px;
font-size: 35px;
height: 42px;
/* background: red */
}
.ref-no{
width: calc(23.6% - 16px);
left: 31.3%;
top: 13.01%;
}
.vrn{
left: 31.3%;
top: 14.9%;
width: 22.8%;
}
.nop{
left: 31.3%;
top: 16.9%;
width: 63.8%;
}
.nro{
left: 31.3%;
top: 18.9%;
width: 63.8%;
}
.cn{
left: 31.3%;
top: 20.6%;
width: 22.8%;
}
.add{
left: 31.3%;
top: 22.6%;
width: 63.8%;
}
.pc{
left: 31.3%;
top: 24.6%;
width: 22.8%;
}
.nic{
left: 31.3%;
top: 26.6%;
width: 22.8%;
}
.en{
left: 31.3%;
top: 28.5%;
width: 22.8%;
}
.ec{
left: 31.3%;
top: 30.3%;
width: 22.8%;
}
.mm{
left: 31.3%;
top: 32.2%;
width: 22.8%;
}
.dr{
left: 31.3%;
top: 34.1%;
width: 22.8%;
}
.from-day{
left: 36.5%;
top: 37%;
width: 4%;
letter-spacing: 30px;
padding-left: 20px;
}
.from-month{
left: 43.5%;
top: 37%;
width: 4%;
letter-spacing: 30px;
padding-left: 20px;
}
.from-year{
left: 50.5%;
top: 37%;
width: 9.5%;
letter-spacing: 35px;
padding-left: 20px;
}
.to-day{
left: 65.6%;
top: 37%;
width: 4%;
letter-spacing: 30px;
padding-left: 20px;
}
.to-month{
left: 72.7%;
top: 37%;
width: 4%;
letter-spacing: 30px;
padding-left: 20px;
}
.to-year{
left: 79.7%;
top: 37%;
width: 9.5%;
letter-spacing: 35px;
padding-left: 20px;
}
.tc{
left: 31.3%;
top: 40.1%;
width: 22.8%;
}
.sticker-sno {
right: 11%;
left: auto;
top: 72.4%;
height: 35px;
font-size: 30px;
width: 14%;
padding-left: 10px;
}
.sticker-rno {
left: auto;
top: 73.8%;
height: 35px;
font-size: 30px;
width: 23%;
right: 10.6%;
}
.sticker-cno {
left: auto;
top: 75.1%;
height: 35px;
font-size: 30px;
width: 23%;
right: 10.6%;
}
.sticker-cp {
left: auto;
top: 76.3%;
height: 35px;
font-size: 30px;
width: 23%;
right: 10.6%;
}
</style>
</head>
<body>
<img src="{{asset('images/td.jpg')}}" alt="" style="width:100%">
<div class="ref-no pa">155dds5544</div>
<div class="vrn pa">A0E4974</div>
<div class="nop pa">Abbas Abdulla</div>
<div class="nro pa">Abbas Abdulla asas sadasd dasdsad</div>
<div class="cn pa">9100074</div>
<div class="add pa">157/85 A, Sassssss, asdawdw, wewdwds, sssdw</div>
<div class="pc pa">2547852</div>
<div class="nic pa">585441154311</div>
<div class="en pa">84561215842131</div>
<div class="ec pa">250cc</div>
<div class="mm pa">TKS2587AS</div>
<div class="dr pa">22/08/2016</div>
<div class="from-day pa">14</div>
<div class="from-month pa">08</div>
<div class="from-year pa">2016</div>
<div class="to-day pa">22</div>
<div class="to-month pa">04</div>
<div class="to-year pa">2025</div>
<div class="tc pa">8049841564</div>
<div class="sticker-sno pa">8049841564</div>
<div class="sticker-rno pa">789456513</div>
<div class="sticker-cno pa">548932115</div>
<div class="sticker-cp pa">10 Years</div>
</body>
</html>
但是当收到电子邮件时,图像将被删除。在没有$pdf->setOptions(['dpi' => 300 ]);
的情况下, pdf 会随图像一起加载,但是设置pdf对齐方式时我需要启用此选项,是否有解决此问题的方法?
谢谢。
答案 0 :(得分:0)
通过调用公共路径并将图像路径连接到我的视图中,可以解决此问题
{{public_path().'/images/td.jpg'}}
感谢所有回答我的问题的人
答案 1 :(得分:0)
我通过将图像转换为base64解决了这个问题。就我而言,我只是使用了在Google上找到的转换器,因为我的图片是静态的,但是如果必须动态转换,则可以使用它
$path = 'myfolder/myimage.png';
$type = pathinfo($path, PATHINFO_EXTENSION);
$data = file_get_contents($path);
$base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);