PDF invoice

  • Posts: 8
  • Thank you received: 0
  • Hikashop Business
5 days 2 hours ago #372000

-- HikaShop version -- : 6.4.1
-- Joomla version -- : 6.1
-- PHP version -- : 8.4
-- Browser(s) name and version -- : Edge Version 148.0.3967.70
-- Error-message(debug-mod must be tuned on) -- : No image in invoice.php / pdf

Hi team,

today I am trying to change the layout etc in invoice.pdf

But I cant get my image to show in the pdf.

Please can you let me know what I need to do?

I am using the invoice.php in: plugins/hikashop/attachinvoice/attachinvoice

My code:
<!-- STORE LOGO -->
<?php
$logoPath = JPATH_ROOT . '/images/xxx.jpg';
?>
<?php if (is_file($logoPath)) : ?>
<div style="text-align:left; margin-bottom:20px;">
<img src="<?php echo $logoPath; ?>" style="width:300px; height:auto;" alt="Logo">
</div>
<?php else : ?>
<div style="color:red; font-size:10px;">
Logo not found: <?php echo $logoPath; ?>
</div>
<?php endif; ?>
<!-- EO STORE LOGO -->

All I am getting is this colored square in the attached image file :(



Kind regards
Hans Peter Betzler

Attachments:

Please Log in or Create an account to join the conversation.

  • Posts: 8
  • Thank you received: 0
  • Hikashop Business
5 days 1 hour ago #372004

Hi team,
thanks to ChatGPT i got a code that works.

Would you like to tell me please is this code save to use?

<!-- STORE LOGO -->
<?php
$logoPath = JPATH_ROOT . '/images/logo/logo.jpg';

if (is_file($logoPath)) {
$logoData = base64_encode(file_get_contents($logoPath));
$logoInfo = getimagesize($logoPath);

if ($logoInfo !== false) {
$mime = $logoInfo;
?>
<div style="text-align:left; margin-bottom:20px;">
<img
src="data:<?php echo $mime; ?>;base64,<?php echo $logoData; ?>"
style="width:170px; height:auto;"
>
</div>
<?php
}
}
?>
<!-- EO STORE LOGO -->


Kind regards
Hans Peter Betzler

Please Log in or Create an account to join the conversation.

  • Posts: 85617
  • Thank you received: 14037
  • MODERATOR
4 days 13 hours ago #372005

Hello,

Yes, base64 is safe. HTML2PDF has an explicit code path for "data:" image sources (it base64-decodes them internally before drawing), so this is a perfectly legitimate way around the file path issue.

For context on what you were seeing: the pinkish-gray square is the placeholder HTML2PDF draws when it cannot actually load an image. Our PDF plugin tries to make image loading reliable by detecting img src attributes that point at your site URL and rewriting them to the equivalent local filesystem path (so the library reads the file directly instead of going through HTTP). It also probes each image with getimagesize() and logs an "Image not accessible" warning to the HikaShop log when it fails. But that whole machinery only helps when the underlying file is actually readable by the PHP process; if it is not (file permissions, open_basedir restriction, or anything else that blocks the read) the placeholder is the final result. Base64 sidesteps all of that because the bytes travel inside the HTML itself, no file lookup is needed at PDF time, so it works in environments where direct path access does not.

One bug to fix in your snippet: "$mime = $logoInfo;" assigns the whole array returned by getimagesize instead of the MIME type, which produces "data:Array;base64,..." in the src attribute. You want the "mime" index:

$mime = $logoInfo['mime'];

The rest is fine.

Please Log in or Create an account to join the conversation.

Time to create page: 0.195 seconds
Powered by Kunena Forum