]> git.parisson.com Git - pdf.js.git/commitdiff
Add back basic printing support for non-moz browsers.
authorBrendan Dahl <brendan.dahl@gmail.com>
Thu, 12 Jul 2012 17:31:20 +0000 (10:31 -0700)
committerBrendan Dahl <brendan.dahl@gmail.com>
Thu, 12 Jul 2012 17:31:20 +0000 (10:31 -0700)
Shadow/cache supports browsing.
Destroy pages on error and only abort if supported.

l10n/en-US/viewer.properties
web/viewer.css
web/viewer.js

index ce268a1133f5c8df95c8907d83ba25585beb6540..1c4dd1cde61fc4b21e861aceabfc58c1fa616c38 100644 (file)
@@ -88,4 +88,4 @@ loading_error=An error occurred while loading the PDF.
 text_annotation_type=[{{type}} Annotation]
 request_password=PDF is protected by a password:
 
-printing_not_supported=Warning: Printing is not supported by this browser.
+printing_not_supported=Warning: Printing is not fully supported by this browser.
index b57af059110e0e5aa52d313e78ced526ebb7ecac..80a8c5a40d66f818899bfac45132240de24f35da 100644 (file)
@@ -1122,13 +1122,37 @@ canvas {
 }
 
 @media print {
-  #outerContainer {
+  /* Rules for browsers that don't support mozPrintCallback. */
+  #sidebarContainer, .toolbar, #loadingBox, #errorWrapper, .textLayer {
     display: none;
   }
-  #printContainer {
+
+  #mainContainer, #viewerContainer, .page, .page canvas {
+    position: static;
+    padding: 0;
+    margin: 0;
+  }
+
+  .page {
+    float: left;
+    display: none;
+    -webkit-box-shadow: none;
+    -moz-box-shadow: none;
+    box-shadow: none;
+  }
+
+  .page[data-loaded] {
+    display: block;
+  }
+
+  /* Rules for browsers that support mozPrintCallback */
+  body[data-mozPrintCallback] #outerContainer {
+    display: none;
+  }
+  body[data-mozPrintCallback] #printContainer {
     display: block;
   }
-  canvas {
+  #printContainer canvas {
     position: relative;
     top: 0;
     left: 0;
index 377a4fc7e7e3e25a1466d01e53fb8ceebe47b8e8..f75701816987cb5d826a88d5d85e1a4db19c5e82 100644 (file)
@@ -381,7 +381,13 @@ var PDFView = {
 
   get supportsPrinting() {
     var canvas = document.createElement('canvas');
-    return 'mozPrintCallback' in canvas;
+    var value = 'mozPrintCallback' in canvas;
+    // shadow
+    Object.defineProperty(this, 'supportsPrinting', { value: value,
+                                                      enumerable: true,
+                                                      configurable: true,
+                                                      writable: false });
+    return value;
   },
 
   open: function pdfViewOpen(url, scale, password) {
@@ -1051,10 +1057,12 @@ var PDFView = {
   beforePrint: function pdfViewSetupBeforePrint() {
     if (!this.supportsPrinting) {
       var printMessage = mozL10n.get('printing_not_supported', null,
-                         'Warning: Printing is not supported by this browser.');
+          'Warning: Printing is not fully supported by this browser.');
       alert(printMessage);
       return;
     }
+    var body = document.querySelector('body');
+    body.setAttribute('data-mozPrintCallback', true);
     for (var i = 0, ii = this.pages.length; i < ii; ++i) {
       this.pages[i].beforePrint();
     }
@@ -1412,7 +1420,11 @@ var PageView = function pageView(container, pdfPage, id, scale,
         console.error(error);
         // Tell the printEngine that rendering this canvas/page has failed.
         // This will make the print proces stop.
-        obj.abort();
+        if ('abort' in object)
+          obj.abort();
+        else
+          obj.done();
+        self.pdfPage.destroy();
       });
     };
   };