You can execute a GET request (for example, use window.open () and pass a URL or use AJAX) and put the returned HTML content in a new window. Then use
Window.print () . Then just close the window when done.
You can link this directly into a single view by adding something to the body, but I prefer to use JavaScript in these cases. This forces the project to act as a reusable object or service that can be used for several types. In other words, you are customizing the controller model, but there is no representation. Instead, JavaScript works as a view.
Keep in mind that HTML is not a print format. Therefore, if you need to control the layout, you should use printing technology such as PDF. XSLT provides excellent tools for creating both HTML and PDF files using the same data, although creating XSLT templates is much more work than for step-by-step window.print
Personally, I have an MVC page acting as a service that accepts URL parameters. The page intercepts Adobe XSL-FO and uses parameters to output the output.
source share