I'm dealing with an ionic 5 app that was built as a web app. There's no mobile component to it.
I need to allow users to print a page. When I have a print button and associated with a function like the one below, it only prints the viewable area.
printPage() {
window.print();
}
Given the amount of content on the screen, I can tell that this document should be 2-3 pages long.
I see that there's a cordova-plugin-printer
plugin, but it's meant for printing from a mobile device.
What's the proper way to get the entire DOM printed?
Supported platforms For Android, Ionic supports Android 4.4 and up. For iOS, Ionic supports iOS 10 and up. Ionic 2 supports the Universal Windows Platform for building Windows 10 apps. Ionic Framework, based on Angular.
This project combines the Electron Framework with the Ionic Framework and provides a starter for building out an app that can run on either the desktop (macOS, Windows and Linux), a browser or mobile devices (iOS and Android). You can use this application to build and run on one or all of these platforms.
That might happen, because of a scrollable div, or something like that, nested in the body.
To get around this, you could manually select what to print by doing something like this answer from another StackOverflow question:
printPage() {
var mywindow = window.open('', 'PRINT', 'height=400,width=600');
mywindow.document.write('<html><head><title>' + document.title + '</title>');
mywindow.document.write('</head><body>');
mywindow.document.write(document.getElementById('#printArea').innerHTML);
mywindow.document.write('</body></html>');
mywindow.document.close(); // necessary for IE >= 10
mywindow.focus(); // necessary for IE >= 10*/
mywindow.print();
mywindow.close();
}
Link to the original answer: https://stackoverflow.com/a/2255438/9150652
I recently faced a similar situation and I ended up creating an angular component in my project, which is inspired by e-ngx-print.
The only limitation is that you will have to pass a *.css
file to this component for the section you want to print.
I have created a stackblitz for you, have a look and see if it's useful for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With