【发布时间】:2017-04-01 16:36:43
【问题描述】:
我正在尝试使用 laravel dom pdf 生成 pdf。当我下载我的 pdf 时,它不显示我的图像。它显示找不到图像或类型未知。但在浏览器中它显示正确。我在堆栈中关注了其他相应的问题。我已启用$isRemoteEnabled = true; 我该如何解决这个问题?
这是我的pdfview:
<html>
<head>
{{--<link rel="stylesheet" href="{{ URL::to('css/style.css') }}">--}}
<style>
/*pdf view start*/
.pdf-content{
/*pdf body*/
width: 100%;
height: 100%;
background-color: #d3d3d3;
}
.pdf-doctor{
/*for doctor*/
border-bottom: 1px dashed gray;
}
.rx{
float: left;
margin-top: 5px;
width: 100px;
height:100px;
}
.rx img{
width: 100px;
height:100px;
}
.doctor-info p{
text-align: center;
}
/*{{--for patient start--}}*/
.pdf-patient{
margin-top: 7px;
border-top: 1px dashed gray;
height: 30px;
width: 100%;
}
.pdf-patient h4{
float: left;
display: inline;
color: #0000cc;
}
.pdf-patient-name-date{
float: left;
margin-left: 76px;
margin-top: 7px;
width: 45%;
}
.pdf-test{
/*for test*/
margin-top: 50px;
height: 20em;
width: 100%;
}
.pdf-test h4{
margin-left: 76px;
/*display: inline;*/
color: #0000cc;
}
.pdf-test-list{
border: 1px solid black;
float: left;
margin-left: 116px;
width: 40%;
}
.pdf-test-list p{
margin-left: 15px;
padding-top: 5px;
}
.pdf-test-done{
border-top: 1px solid black;
border-right: 1px solid black;
border-bottom: 1px solid black;
float: left;
/*margin-left: 76px;*/
/*margin-top: 15px;*/
height: 37px;
width: 10%;
}
.pdf-comments{
/*for comment*/
margin-top: 50px;
height: 30px;
width: 100%;
}
.pdf-comments h3{
/*for comment*/
margin-left: 76px;
/*display: inline;*/
color: #0000cc;
}
/*pdf view end*/
</style>
</head>
<body>
<div class="pdf-content">
<div class="pdf-doctor">
<div class="rx">
<img src=" {{ url("/images/rx1.png") }}">
{{--{{URL::asset('/image/propic.png')}}--}}
</div>
{{--for doctor--}}
<div class="doctor-info">
<p>Doctor's name here</p>
<p>Doctor's degree here</p>
<p>Doctor's Address here</p>
<p>Doctor's Mob here</p>
</div>
</div>
<div class="pdf-patient">
{{--for patient--}}
<div class="pdf-patient-name" style="float: left;">
<h4 style="display: inline;"><i>Patient name</i>:  </h4>
<h4 style="display: inline;">{{ $patients->name }}</h4>
{{--style="text-decoration: underline; text-decoration-style: dotted;"--}}
</div>
<div class="pdf-patient-date" style="margin-left: 175px;">
<h4 style="display: inline;"><i>Date</i>:  </h4>
<h4 style="display: inline;">{{ $patients->created_at }}</h4>
</div>
</div>
<div class="pdf-test">
{{--for test--}}
<h4>Tests</h4>
<div style="height: 5px;"></div>
{{--@foreach($patients as $patient)--}}
<div class="pdf-test-list">
<p>{!! nl2br($patients->test) !!}</p>
</div>
{{--<div class="pdf-test-done">--}}
{{--<p>tik</p>--}}
{{--</div>--}}
{{--@endforeach--}}
</div>
<div class="pdf-comments">
{{--for comment--}}
<h3 >Comments</h3>
</div>
</div>
</body>
</html>
我的控制器:
public function PdfView(Request $request, $patient_id)
{
$patients = Patient::where('id', $patient_id)->first();
$pdf = PDF::loadView('pdfview', ['patients'=>$patients]);
return $pdf->download('pdfview.pdf');
}
我的图片在public/images/rx1.png 中,pdfview 在views 文件夹中。我该如何解决这个问题?
【问题讨论】:
-
恕我直言,建议:尝试使用同一作者的 laravel/snappy,相对于 DomPDF,它的功能更强大,布局复杂,非常基础。
-
@dparoli 我一开始使用的是 laravel/snappy。但是当我添加图像时它给了我 processtimeouterror,我试图通过增加时间段来解决它并按照github.com/KnpLabs/snappy/issues/169这个链接。但无法解决问题。这就是我现在使用 dompdf 的原因。你能告诉我如何在 dompdf 中解决这个问题吗?
-
图片是png的吗?如果是,则使用编辑器将其转换为 jpeg 并相应更改扩展名
-
@dparoli 如你所说,我将其转换为 jpeg,但仍然显示同样的问题。
-
最后一次尝试:仅在 pdf 视图中对图像使用绝对路径而不是 URL
标签: php pdf laravel-5.4