0

I am trying to generate a PDF with mendix but I can not find any way to add my charts to the PDF. The charts I have already built for my dashboard now I just want to include them in a PDF report that is sent to the management.

Any clues are welcomed.

Willem
  • 376
  • 2
  • 8
Amit
  • 13
  • 1

2 Answers2

0

Adding chart to PDFs is not supported natively by Mendix. To achieve your desired functionality you will need to rely on third party extensions.
I recommend Templator - Document (PDF) generation alternative which you can find in the Mendix app store https://appstore.home.mendix.com/link/app/114043/. With this module you can use the same charts that you have built for a page in the generated PDF.
Make sure to check the starting guide at https://www.notion.so/gajduk/Templator-d35db3ba165346e3b243d6695636ccd4

Willem
  • 376
  • 2
  • 8
0

Alternatively, you can send a page to the printer with some simple Javascript. That way the user can either print it to page or to pdf.

This allows you to save anything to pdf that you would like to. You may need some lines of code to only print those parts of the UI that you are interested in.

I once used this:

    var printContents = document.querySelector('.'+ className).innerHTML;
    var originalContents = document.body.innerHTML;

    const frag = new DocumentFragment();
    while (document.body.firstChild) {
        frag.appendChild(document.body.firstChild); // Moves it
    }

    document.body.innerHTML = printContents;
    window.print();
    document.body.innerHTML = "";
    while (frag.firstChild) {
        document.body.appendChild(frag.firstChild); // Moves it
    }

It will select a page element with a provide class name (className) and replaces the entire page with the content of this page element. Next the page will be sent to the printer. When you finish printing, the original page will be restored.

MWB
  • 1,830
  • 1
  • 17
  • 38