From 8ce96f8bdec5ab5ff5d8a211055eaae9eb5315b5 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Wed, 19 Oct 2016 15:26:49 -0400 Subject: [PATCH] Experiment printing html via canvas -> base64 Signed-off-by: Bill Erickson --- Open-ILS/src/templates/staff/base.tt2 | 1 + Open-ILS/src/templates/staff/base_js.tt2 | 4 ++++ Open-ILS/src/templates/staff/css/print.css.tt2 | 5 +++-- Open-ILS/web/js/ui/default/staff/services/print.js | 25 +++++++++++++++++++++- 4 files changed, 32 insertions(+), 3 deletions(-) diff --git a/Open-ILS/src/templates/staff/base.tt2 b/Open-ILS/src/templates/staff/base.tt2 index 7f4c64a958..db4424fab3 100644 --- a/Open-ILS/src/templates/staff/base.tt2 +++ b/Open-ILS/src/templates/staff/base.tt2 @@ -50,5 +50,6 @@ +
diff --git a/Open-ILS/src/templates/staff/base_js.tt2 b/Open-ILS/src/templates/staff/base_js.tt2 index af92b80715..fd3a579ed4 100644 --- a/Open-ILS/src/templates/staff/base_js.tt2 +++ b/Open-ILS/src/templates/staff/base_js.tt2 @@ -16,6 +16,10 @@ + + + + diff --git a/Open-ILS/src/templates/staff/css/print.css.tt2 b/Open-ILS/src/templates/staff/css/print.css.tt2 index 5410ba990b..f8c76bea5a 100644 --- a/Open-ILS/src/templates/staff/css/print.css.tt2 +++ b/Open-ILS/src/templates/staff/css/print.css.tt2 @@ -4,10 +4,11 @@ head { display: none; } /* just to be safe */ body div:not([id="print-div"]) { display:none } div { display: none } -#print-div { display: block } -#print-div div { display: block } +#print-div { display: inline-block } +#print-div div { display: inline-block } #print-div pre { border: none } + [%# vim: ft=css %] diff --git a/Open-ILS/web/js/ui/default/staff/services/print.js b/Open-ILS/web/js/ui/default/staff/services/print.js index fa60193683..0029a0c9bc 100644 --- a/Open-ILS/web/js/ui/default/staff/services/print.js +++ b/Open-ILS/web/js/ui/default/staff/services/print.js @@ -74,8 +74,17 @@ function($q , $window , $timeout , $http , egHatch , egAuth , egIDL , egOrg) { return promise.then(function(html) { + var content_type = args.content_type; + if (content_type == 'text/html') content_type = 'image/png'; + + /* + console.log(html); + console.log(content_type); + return; + */ + return egHatch.remotePrint(context, - args.content_type, html, args.show_dialog)['catch']( + content_type, html, args.show_dialog)['catch']( function(msg) { // remote print not available; @@ -185,9 +194,23 @@ function($q , $window , $timeout , $http , egHatch , egAuth , egIDL , egOrg) { // resolve with the compiled HTML from our // print container + var printNode = resp.contents()[0].parentNode; + document.getElementById('test-print').appendChild(printNode); + html2canvas(printNode, { + onrendered : function(canvas) { + var img = canvas.toDataURL("image/png"); + //document.body.removeChild(printNode); + img = img.split(/,/)[1]; // trim URL bits + img = img.replace(/=/g, ''); // trim trailing ='s + deferred.resolve(img); + } + }); + + /* deferred.resolve( resp.contents()[0].parentNode.innerHTML ); + */ }); return deferred.promise; -- 2.11.0