Custom invoice template PDF generation fails (but works with default templates)

Version ie <v5.11.40>

Environment Docker

Checklist

  • Can you replicate the issue on our v5 demo site https://demo.invoiceninja.com or Invoice Ninja? Getting an “invalid data access” error in the editor when trying to create the custom invoice design
  • Have you searched existing issues? yes
  • Have you inspected the logs in storage/logs/laravel.log for any errors? yes

Describe the bug

Hi,
I’m new to InvoiceNinja (using self-hosted docker setup). Since I already have a time tracking tool I’m quite happy with (Toggl), I only want to use InvoiceNinja for generating my monthly invoices (I’ve got a consulting business and charge my services per hour). I added my clients with all the necessary information (also default rates, tax, country etc). I’ve set up an automation that collects my monthly hours from toggle, then aggregates the values per client and creates an invoice in InvoiceNinja for each client (using the API endpoint /api/v1/invoices) - this works pretty well.

For reference, this is the object I send to the create_invoice endpoint:

{
  "client_id": "[INVOICENINJA CLIENT ID]",
  "custom_value1": "[A CUSTOM VALUE]",
  "tax_name1": "USt.",
  "tax_rate1": 19.00,
  "line_items": [
    {
      "quantity": [HOURS],
      "product_key": [DESCRIPTION OF MY SERVICE],
      "cost": [MY HOURLY RATE],
      "type_id": 2,
      "tax_id": 2
    }
  ],
  "uses_inclusive_taxes": false,
  "date": "[TODAY]",
  "due_date": "[DATE IN THE FUTURE]"
}

I’m able to pre-view and download invoice pdfs as expected - as long as I stick to one of the existing invoice templates!

And this is where my problem begins…
I got my custom invoice design which I want to keep, so I’ve spent quite some time to re-build this custom design in InvoiceNinja. Inside the template, I use TWIG and the pre-defined variables to populate the template. In the „custom invoice builder“, I see the preview populated with placeholder data (of „A client called Bob“) - so this seems to work exactly as expected (see attached screenshot).

However, when I set this custom template as my default template and want to view or download my invoices as PDF - nothing happens.

In the console, I see the following error when I try to download the invoice pdf (see also second screenshot):

[Exception: InvalidStateError: Failed to read the 'responseXML' property from 'XMLHttpRequest': The value is only accessible if the object's 'responseType' is '' or 'document' (was 'arraybuffer'). at XMLHttpRequest.invokeGetter (<anonymous>:3:28)]

Does anyone have an idea what the issue might be? Since it’s working perfectly fine with the default templates, there is obviously no issue with the pdf engine. I assumed, that I might be using some values in the template, which are not available in my invoice, but this is also not the case.

Any help is highly appreciated!

Hi,

Are there any details about the 500 error in storage/logs?

Hey @hillel,
Thanks for your message! The invoiceninja.log shows the following when I try to display the pdf:

production.INFO: DOMDocumentFragment::appendXML(): Entity: line 15: parser error : Opening and ending tag mismatch: br line 11 and div

I’m using multiple <br /> tags in the template body, so I first replaced them with <br> - however, the message still appears and the pdf is not being generated.

Then, I removed the first <br> tag, and then new log shows now:

production.INFO: DOMDocumentFragment::appendXML(): Entity: line 27: parser error : Opening and ending tag mismatch: br line 27 and p

So basically it jumps to the next row where there is a <br> tag. Any idea what I can do to use <br> tags anyway?

Replacing all <br> tags solved the problem, by the way!

1 Like

Glad to hear it, thanks for the update!