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.