Printing
Smart WebView supports printing the content currently displayed in the WebView using the native Android print framework.
How to Trigger Printing
Printing is initiated from your web content by using a hyperlink with the special URL scheme print:.
HTML Example:
<a href="print:">Print this Page</a>
<!-- Or use a button with JavaScript -->
<button onclick="window.location.href='print:'">Print Report</button>
How it Works
- A user clicks a
print:link in the WebView. - The
shouldOverrideUrlLoadingmethod inMainActivity.javaintercepts this URL. - It calls the
Functions.print_pagemethod. - This method uses the Android
PrintManagerservice to create a print job from the current WebView content. - The standard Android print preview screen appears, allowing the user to select a printer, save as a PDF, and adjust settings.
The quality of the printout depends on how well your webpage’s CSS is optimized for print media (e.g., using @media print styles).
Requirements
- Android 4.4 (KitKat, API 19) or higher.
- The device must have print services enabled or configured (e.g., Cloud Print, Wi-Fi Direct printing, or Save as PDF).