UNPKG

print-js

Version:

A tiny javascript library to help printing from the web.

127 lines (116 loc) 3.09 kB
<html> <script src='./dist/print.min.js'></script> <script type="text/javascript"> function printPdf() { printJS('test.pdf'); } function printPdfWithModal() { printJS({ printable: 'test.pdf', type: 'pdf', showModal: true }); } function printHtml() { printJS({ printable: 'test', type: 'html' }); } function printHtmlCustomStyle() { const style = '@page { margin: 0 } @media print { h1 { color: blue } }' printJS({ printable: 'test', type: 'html', style: style, scanStyles: false }); } function printHtmlCss() { printJS({ printable: 'test', type: 'html', css: 'test.css', scanStyles: false }); } function printJson() { let data = [ { test1: 'Test1 string', test2: 'Test2 string' }, { test1: 'more Test1 string', test2: 'more Test2 string' } ] printJS({printable: data, properties: ['test1', 'test2'], type: 'json'}) } function printStyledJson() { let data = [ { test1: 'Test1 string', test2: 'Test2 string' }, { test1: 'more Test1 string', test2: 'more Test2 string' } ] printJS({printable: data, properties: ['test1', 'test2'], type: 'json', gridStyle: 'border: 2px solid #3971A5;', gridHeaderStyle: 'color: red; border: 2px solid #3971A5;'}) } function printNestedJson() { let data = [ { test1: 'Test1 string', test2: { a: 'Test2 object, a property', } }, { test1: 'more Test1 string', test2: { a: 'more Test2 object, a property', } } ] printJS({printable: data, properties: ['test1', 'test2.a'], type: 'json'}) } </script> <body> <section id="test" class="test"> <h1>Print.js Test Page</h1> <p> <button onClick='printPdf();'> Print PDF </button> <button onClick='printPdfWithModal();'> Print PDF with Loading Modal </button> </p> <p> <button onClick='printHtml();'> Print HTML </button> <button onClick='printHtmlCustomStyle();'> Print HTML with custom style </button> <button onClick='printHtmlCss();'> Print HTML with custom css </button> </p> <p> <button onClick='printJson();'> Print JSON </button> <button onClick='printStyledJson();'> Print Styled JSON </button> <button onClick='printNestedJson();'> Print Nested JSON </button> </p> </section> </body> </html>