Margin-left not working anymore


I don’t know why and how this is even possible, but when I tried to regenerate an invoice today, it was not possible, I was getting a php error pointing to mPDF. A few days ago, it was working fine, I haven’t changed or updated anything, just suddenly I couldn’t generate an invoice anymore:

A PHP Error was encountered

Severity: Notice

Message: Undefined index: miw

Filename: src/Mpdf.php

Line Number: 20794


The culprit is setting a margin:

margin-left: 2cm;

inside the


        @page :first {
            background: url("");

        @page {
            margin-left: 2cm;
            background: url("");

section. How is this even possible? I can’t currently use the margins anymore, as soon as I add them, it’s not working anymore and I get a bunch of the A PHP Error was encountered-blocks

Is invoiceplane somehow updating or changing stuff in the background maybe with composer or any other tool?
Can I somehow see, what version of e.g. mPDF is in use?

[Solved]Margin on pdf documents

1.5.5 currently ships with a modified version 6 of mPDf. The next version will include mPDF 7 which may solve this problem.


the strange thing is, that it has worked, but it stopped working. Is there an aprox. release date for the next version? Currently invoiceplane is not usable with this issues (margin not usable and full-size background image hides footer)


Hope that I can release 1.5.6 at the end of this week

Error when emailing invoice

@Kovah I’ve updated invoiceplane to 1.5.6 now. Checked on the Backends settings and also the package.json shows the 1.5.6 version.
But the issues are still all in here. Again when adding margins, the page crashed with the “A PHP Error was encountered” message. When margins removed, it works.
Also the background image still hides the footer text. You’ve mentioned you are using a modified version of “mpdf”, so is it modified also in the 1.5.6 version of invoiceplane?
I even don’t know if this is still a bug or only on my side somehow.


Modified means that assets were removed that InvoicePlane does not use like binary files for QR codes. The rest of the mPDF codebase is untouched and equals the code of version 7.0.3.


Okay @Kovah I need a solution now, I’m fighting with this over two weeks now. Nobody in this community is confirming this issues, seems nobody have these issues or nobody have tested it, You are willing to help, thank you for that, but I need a clear statement like, “yes here, I’ve tested the background and margin stuff and it is working so it must be your setup/or it is not working like you said this is definitely a bug”. I know and recognize it is pointing towards mpdf, as this issues are on generating a pdf.
15 days ago I’ve already submitted an issue on github for mpdf:
But as others get an answer very soon, my submit is getting ignored.
So what should I do? Invoiceplane looks very promising to me, but I can’t get it to work (likely just because of mpdf).


I can’t do anything else than trying to reproduce this issue but you may have to wait as I have several other things to do at the moment.


Yeah that would be awesome if you could. For sure, I will wait. Thank you a lot!



Can you please share with us the whole template you’re using (remove any confidential data please) with CSS (if custom).

It will be easier for us to have the same base as you to help and provide a solution (fix ? :D)



@Maxime_GRIMLER yeah sure. It’s almost the default one. I’ve entered here a random url for a background image from the internet. Inside the invoice-details div I’ve a custom field. You can just drop it in case you don’t want to create it as it is not causing the issue. And that’s it.
You will see, if a background image is set, the footer is hidden. The footer is set exactly where I’ve setup the default template in the settings.
I’m curious to know if it will behave the same on your system.

myTemplate.css (216 Bytes)
myTemplate.php (8.9 KB)


For the margin-left I should take the same as your first post right ? (it doesn’t appear in your CSS that’s why I ask)


ouhh yeah sorry, I’ve removed it so that it generates the pdf, otherwise it dies. Everything else is the same, just test it with:


        @page {
            margin-top: 3.5cm;
            margin-bottom: 2.54cm;
            margin-left: 2cm;
            margin-right: 2cm;
            background: url("");

        @page :first {
            background: url("");



Thanks, I have a PR to finish before and will try to have a look on my dev env


Firstable for the background which hides the footer problem is known from mPDF

The actual fix I found is to set the background in the body instead of @page selector

    body {
        background: url("");


(Maybe you can play with the “odd/even” parameters to have multiple background …)

I’m checking the margin problem right now


So concerning your margin-left

From what I have understand is that there is a calcul in the mPDF library which blocks assigning more than 1.4cm in margin-left.
If you set 1.3cm, then it works and the PDF will generate, if you set 1.4cm and more then it will throw the exception.

To be honest the file is really really big at mPDF and it would take me ages to understand the real problem.
I would be you I would contact (again sorry) mPDF via the issue tracker (maybe a new issue now we have more data ?) and also in stackoverflow

I can’t explain why from one day to another it stopped working …
If 1.3cm is enough for you then say hurra and have fun, if not I’m sorry but I won’t have time to debug mPDF :confused:



@Maxime_GRIMLER background-image I’ve looked through the issues but haven’t seen this one. Okay yeah, background on body is possible, but not with the pseudo selector :first. Which isn’t that bad, I can work around that, to use only one background.

margin-left, yeah you are right, for 1.3cm it won’t crash, but this is really useless. It can’t be set on body, so I’ve set it on @page but as soon as I add a margin, it doesn’t matter if top, left, right or bottom, the background which is set on body disappears. mPDF seems really broken/buggy if you ask me.

Never mind, you InvoicePlane guys are doing a great job, I will see what I’m going to do now, maybe a last issue submit, if I’m getting ignored again, then I will have to to look for another invoicing application


Did you try to set the margin in a div container just after your body ?
for example

<body><div id="margin">blablabla</div></body>

Then the whole document will be inside the div and maybe you can apply a margin on it without breaking mPDF ?
In my opinion it’s more the @page selector which is broken :confused:

Anyway on stackoverflow there is often an answer so try on stackoverflow :slight_smile:


yep, tested to wrap all the content inside body into a div and give it a margin via css. mPDF crashes also. I will ask on stackoverflow: