Experiment printing html via canvas -> base64 user/berick/webstaff-hatch-canvas-print
authorBill Erickson <berickxx@gmail.com>
Wed, 19 Oct 2016 19:26:49 +0000 (15:26 -0400)
committerBill Erickson <berickxx@gmail.com>
Wed, 19 Oct 2016 19:26:49 +0000 (15:26 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/templates/staff/base.tt2
Open-ILS/src/templates/staff/base_js.tt2
Open-ILS/src/templates/staff/css/print.css.tt2
Open-ILS/web/js/ui/default/staff/services/print.js

index 7f4c64a..db4424f 100644 (file)
@@ -50,5 +50,6 @@
     <!-- content printed via the browser is inserted here for 
          DOM-ification prior to delivery to the printer -->
     <div id="print-div" eg-print-container></div>
+    <div style="display:inline-block" id="test-print"></div>
   </body>
 </html>
index af92b80..fd3a579 100644 (file)
 <script src="[% ctx.media_prefix %]/js/ui/default/staff/build/js/ngToast.min.js"></script>
 <script src="[% ctx.media_prefix %]/js/ui/default/staff/build/js/angular-tree-control.js"></script>
 
+<!-- TODO -->
+<script src="/js/html2canvas.js"></script>                             
+<script src="/js/html2canvas.svg.js"></script>         
+
 <!-- IDL / opensrf (network) -->
 <script src="[% ctx.media_prefix %]/js/dojo/opensrf/JSON_v1.js"></script>
 <script src="[% ctx.media_prefix %]/js/dojo/opensrf/opensrf.js"></script>
index 5410ba9..f8c76be 100644 (file)
@@ -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 
 %]
index fa60193..0029a0c 100644 (file)
@@ -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;