Background-image ignored

Using invoiceplane 1.5.5

I can’t set the background-image to be in the generated pdf. When I change background to background-color and set two different colors in here, it works. I’ve also echo’ed the full path I’m using here in the generated pdf, and it was the correct one, I could easily access the images in the browser. Am I missing something?

    <style>
    @page :first {
        background: url("<?php echo base_url(); ?>assets/core/img/nv_first_page.png");
    }
    @page {
        background: url("<?php echo base_url(); ?>assets/core/img/nv_second_page.png");
    }
    </style>

Hey

Can you please try using a full URL and not the <?php echo base_url(); ?> (not it should not working but just to test) - or maybe an URL from a background on the internet

By the way second test can you try adding !important after the URL like

background: url(“<?php echo base_url(); ?>assets/core/img/nv_first_page.png”) !important;

Regards,

@Maxime_GRIMLER okay tried that. I’ve used to write the full url inside url("…"), also tried with important, but nothing. I can still access the image when entering the full url in my browser.
Changing the url to a background from the internet works.
I’m using invoiceplane in a vpn, with a self signed ssl certificate. I think this is the issue, the url only exist inside the vpn.
But what I don’t get is, above the <style> ... part, there is

<link rel="stylesheet" href="<?php echo base_url(); ?>assets/core/css/MYOWNSTYLESHEET.css">

And this is working fine, so the stylesheet is accessible and used by invoiceplane but not the image :thinking:

1 Like

If you have full control of the server (root access), modify the HOSTS file. Include an entry for your IP FQDN, pointing to the LAN address of your host, e.g.

10.0.1.7 invoiceplane.mydomain.tld

mPDF is trying to resolve the FQDN of your installation to load the file and it is failing to find the address. This is similar to an issue where public facing hosts have trouble with mPDF resolving to the public address and causing the traffic to get caught up in a messy NAT situation.

d

The search limit will be decreased with the next release

https://development.invoiceplane.com/browse/IP-634

@twoup Yes I do have root access. Added the entry but still not working with the image inside “…/assets/core/img/”

Bummer, I hoped that would be an easy fix. Could you try moving the image to the assets/core/css/ directory, and referencing the image by name only in the stylesheet (background: url(imagename.ext); - the default read path for pdf images is that location.

p.s. once you’ve moved the image, it can take a few “Generate PDF” actions to come in to effect. also recommend doing your testing inside a “Private Browsing” or “Incognito” window, to ensure nothing is being cached inside the browser from your earlier attempts. You could also clear your browsing history and data, but private/incognito is less destructive to your other browsing habits :slight_smile:

nope, not working either. I’ve tried inside a private browsing window, regenerating a couple times.
The images are in assets/core/css
The entry is in inside the <head> section of the myOwnTemplate.php:

    <style>

        @page :first {
            background: url("first_page.png");
            background-image-resize:6;
        }

        @page {
            background: url("https://public.mydomain.com/img/second_page.png");
            background-image-resize:6;
            
        }
    
    </style>

@page :first background is NOT working, @page background is working. So I could live with that, keeping the img in a public share, I mean it’s not a good solution but at least it works that way.

IP 1.5.6 will update mPDF (PDF engine). Maybe this is a bug and then will be solved.

1 Like