Reputation: 1131
I am trying to generate a pdf using laravel dom pdf. When i download my pdf it does not show my image. It shows Image not found or type unknown. But in browser it shows correctly. I have followed other corresponding questions in stack. I have enabled $isRemoteEnabled = true;
How can i resolve this?
This is my 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>
my Controller:
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');
}
my image is in public/images/rx1.png
and pdfview is in views folder. How can i resolve this?
Upvotes: 1
Views: 2877
Reputation: 7
Got This issue if there are spaces in the image name or URL's
you can either do this
isRemoteEnabled: true
or
$image = Image name.jpg; (causing error)
$image = Image%20name.jpg; (is okay)
So replace the image-name, which have spaces in it with %20 it will be solved.
$image = str_replace(' ', '%20', $items->image);
Upvotes: 0
Reputation: 9171
Try to use absolute paths for images, and probably for others resources, like css and javascripts if they are not loaded.
For this its better to have a layout dedicated to pdf export with absolute paths to load resources.
As an alternative you can try to set:
isRemoteEnabled: true
in config/dompdf.php and use your normal view layout.
Upvotes: 1