The same code works on server and pdf shows images, but not locally(Laragon + Win 10) , also when I tried to dump the html to be provided for render pdf on localhost it is also showingthe proper images, but the MPDFfinal rendered output not showing images in pdf, even it takes the css stylesheet file, but not images,
One more thing is CDN images works if I used with src on localhost.
From My CI4 Controller
public function htmlToPDF()
{
// Fetch user data from the database
$editor_id = session()->get('id');
$model = new UserModel();
$editor = $model->where('id', $editor_id)->first();
// Prepare data to pass to the view
$data['editor'] = $editor;
$data['bread'] = 'Profile';
// Render the view to HTML
$html = view('pdf-view', $data);
// Debugging: Output HTML to inspect
// var_dump($html); die();
// Initialize MPDF
$mpdf = new MpdfMpdf([
'mode' => 'utf-8',
'format' => 'A4-L',
'orientation' => 'L',
'tempDir' => sys_get_temp_dir(), // Set temp directory to avoid caching
]);
// Enable HTML input
$mpdf->text_input_as_HTML = TRUE;
// Load CSS stylesheet
$stylesheet = file_get_contents('public/assets/frontend/css/icards.css');
$mpdf->WriteHTML($stylesheet, 1);
// Write HTML content to PDF
$mpdf->WriteHTML($html);
// Output the PDF
$mpdf->Output();
// Terminate script
die();
}
View Code
<table class="w-100">
<tr>
<td class="w-50">
<div class="card">
<img src="<?= base_url('public/assets/card/1.jpg') ?>" class="w-100 img card-bg">
<div class="card-items">
<table>
<tr>
<td colspan="3" class="center">
<img src="<?= base_url('public/uploads/profile/' . $editor['profile_pic']) ?>" class="profile_pic" style="border-radius:50%;" />
<br><br>
<p>पद : विशेष सदस्यत्व </p>
<p></p>
<p></p>
</td>
</tr>
<tr>
<td colspan="3">
<br>
</td>
</tr>
<tr>
<td style="min-width:100px;"> <b>नाव : </b></td>
<td><?= $editor['first_name'] . ' ' . $editor['last_name'] ?></td>
<td></td>
</tr>
<tr>
<td> <b>नोंदणी क्रमांक :</b> </td>
<td><?= $editor['registration_no'] ?></td>
<td></td>
</tr>
<tr>
<td><b>आधार कार्ड क्रमांक :</b> </td>
<td><?= $editor['adhar_card_no'] ?></td>
<td></td>
</tr>
<tr>
<td> <b>मोबाइल क्रमांक :</b> </td>
<td><?= $editor['phone_no'] ?></td>
<td></td>
</tr>
<tr>
<td> <b>पत्ता :</b> </td>
<td><?= $editor['address'] ?></td>
<td></td>
</tr>
</table>
</div>
</div>
</td>
<td class="gap"> </td>
<td class="w-50">
<img src="<?= base_url('public/assets/card/2.jpg') ?>" class="w-100 img card-bg">
</td>
</tr>