Printing in Web viewer

Hi, I attended the last office hour in which @Marcus Swift showed us how to do a print in Webviewer by using a method in chart.js to convert the chart to an image in base64 and display that in another web viewer. It inspires me to explore this library. It works fine using chart.js.

But if we want to print without using chart.js, I think we could use html2canvas, take a screenshot, pass the base64 image back to FileMaker, and show the result in another web viewer. I could preview the image in preview mode. I don’t need to put the image into a container field if the web viewer is the only thing to be printed

The sample code is shown as follows.

import html2canvas from 'html2canvas';

///// your code
// the following code will print the body
html2canvas(document.body).then(function(canvas) {
    let data = canvas.toDataURL();
    FileMaker.PerformScriptWithOption("Print", data, 5);
});