Search code examples
phpcodeigniterpdfdesktop-applicationmpdf

image not showing using mpdf under exeoutput for php


I am using EXEOUTPUT for PHP to create a desktop application using Codeigniter framework. All the web pages are showing image stored in MYSQL BLOB field but only pdf generated with mpdf library fails to show the image.

When I run the same code in a browser, Image is shown. Even when I use base url as http://localhost/applicationname/, image is shown. But when I execute the same code inside Exeoutput for PHP using http://heserver/ as the base url, Image is not shown.

$config['base_url'] = 'http://heserver/';
//$config['base_url'] = 'http://localhost/applicationname/';

I have tried to access the image uploaded in the folders too, they are not accessed either. Does mpdf library needs some location to render the image temporarily before rendering or there is some other issue?

I have tried all the following variants:

$top.='<img width="40px" src="logo.png"/>'; //accessing from file system
$top.='<img width="40px" src="data:image/png;base64,'.base64_encode($this->session->userdata('logo')).'"/>'; //accessing from database
$top.='<img width="30px" src="'.exo_getglobalvariable('HEPubStorageLocation', '').'rs\logo.png" />' //accessing through variable provided by exeoutput4php tool

ob_clean();
header('Content-type: application/pdf');
header('Content-Disposition: inline; filename="'.$billno.'.pdf"');
header('Content-Transfer-Encoding: binary');
header('Accept-Ranges: bytes');
include($_SERVER['DOCUMENT_ROOT']."/application/views/admin/mpdf/vendor/autoload.php");
$mpdf = new \Mpdf\Mpdf();
$mpdf->WriteHTML($top);
$mpdf->SetJS('this.print();');
$mpdf->Output();
exit;

I have also tried an absolute virtual Data folder, but things didnot work.

I have used an image as an external resource, have tried call it by passing subfolder/imagename as src in image tag, but images are not visible.

Please suggest some solution.


Solution

  • Most PDF libraries will fail to embed the images unless you refer to them using the $_SERVER superglobal, because they need not the URI to the image (https://example.com/directory/file.jpg) but the path to the image (/home/user/directory/directory/.../file.jpg).

    try referencing your images (for the purposes of PDF exporting) like:

    <img src="<?php echo $_SERVER['DOCUMENT_ROOT']; ?>/assets/pdf_images/logo.png" border="0" width="174" height="38">
    

    (this is straight from my own code, change the path and attributes to fit your own)