In this walkthrough, you'll learn how to print HTML content from Javascript directly to the client printer without displaying a print dialog i.e. very silently. You'll be able to print HTML content to the Default client printer as well as to any other installed printer at the client machine. This solution works with any browser on Windows OS like IE, Edge, Chrome, Firefox, Opera & Safari as well as on Linux, Raspberry Pi & Mac systems!
The HTML content that we'll print is a simple business card made by pure HTML and CSS markup containing an image. The HTML Card looks like follows:
The HTML printing is performed by following these tasks:
IMPORTANT! html2canvas is not supported by all browsers. Please refer to Browser Compatibility topic.
NOTE: It's important that you specify inline style instead of CSS classes to specifying things like Font Family as well as is a good idea to use Data URI to display images in PNG or JPEG formats.
Print HTML Card from Javascript
This card is 300px x 400px ⇔ 3.125in x 4.17in (300/96 and 400/96 respectivelly)
10px 10px 0 0;"> John Doe
Architect & Engineer
or.