2023-07-18 Easy printing with the afterprint event Resources12345678910111213/* set print page to landscape */@media print{ @page { size: landscape }}/* class to size page to landscape a4 */.print { width: 10in; height: 7.7in; margin: 0 auto;} 1234567891011121314151617181920// sleep functionfunction sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms));}// print variable is a true/false toggle based on a button click// afterprint event toggles page back to normalwindow.addEventListener("afterprint", (event) => { print = false})// print button click eventasync function printPreview() { print = !print if (print) { await sleep(600) window.print() }}