Skip to content

Commit d32906a

Browse files
committed
Add back basic printing support for non-moz browsers.
Shadow/cache supports browsing. Destroy pages on error and only abort if supported.
1 parent 4655ec0 commit d32906a

File tree

3 files changed

+43
-7
lines changed

3 files changed

+43
-7
lines changed

l10n/en-US/viewer.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,4 @@ loading_error=An error occurred while loading the PDF.
8888
text_annotation_type=[{{type}} Annotation]
8989
request_password=PDF is protected by a password:
9090

91-
printing_not_supported=Warning: Printing is not supported by this browser.
91+
printing_not_supported=Warning: Printing is not fully supported by this browser.

web/viewer.css

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,13 +1122,37 @@ canvas {
11221122
}
11231123

11241124
@media print {
1125-
#outerContainer {
1125+
/* Rules for browsers that don't support mozPrintCallback. */
1126+
#sidebarContainer, .toolbar, #loadingBox, #errorWrapper, .textLayer {
11261127
display: none;
11271128
}
1128-
#printContainer {
1129+
1130+
#mainContainer, #viewerContainer, .page, .page canvas {
1131+
position: static;
1132+
padding: 0;
1133+
margin: 0;
1134+
}
1135+
1136+
.page {
1137+
float: left;
1138+
display: none;
1139+
-webkit-box-shadow: none;
1140+
-moz-box-shadow: none;
1141+
box-shadow: none;
1142+
}
1143+
1144+
.page[data-loaded] {
1145+
display: block;
1146+
}
1147+
1148+
/* Rules for browsers that support mozPrintCallback */
1149+
body[data-mozPrintCallback] #outerContainer {
1150+
display: none;
1151+
}
1152+
body[data-mozPrintCallback] #printContainer {
11291153
display: block;
11301154
}
1131-
canvas {
1155+
#printContainer canvas {
11321156
position: relative;
11331157
top: 0;
11341158
left: 0;

web/viewer.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,13 @@ var PDFView = {
381381

382382
get supportsPrinting() {
383383
var canvas = document.createElement('canvas');
384-
return 'mozPrintCallback' in canvas;
384+
var value = 'mozPrintCallback' in canvas;
385+
// shadow
386+
Object.defineProperty(this, 'supportsPrinting', { value: value,
387+
enumerable: true,
388+
configurable: true,
389+
writable: false });
390+
return value;
385391
},
386392

387393
open: function pdfViewOpen(url, scale, password) {
@@ -1051,10 +1057,12 @@ var PDFView = {
10511057
beforePrint: function pdfViewSetupBeforePrint() {
10521058
if (!this.supportsPrinting) {
10531059
var printMessage = mozL10n.get('printing_not_supported', null,
1054-
'Warning: Printing is not supported by this browser.');
1060+
'Warning: Printing is not fully supported by this browser.');
10551061
alert(printMessage);
10561062
return;
10571063
}
1064+
var body = document.querySelector('body');
1065+
body.setAttribute('data-mozPrintCallback', true);
10581066
for (var i = 0, ii = this.pages.length; i < ii; ++i) {
10591067
this.pages[i].beforePrint();
10601068
}
@@ -1412,7 +1420,11 @@ var PageView = function pageView(container, pdfPage, id, scale,
14121420
console.error(error);
14131421
// Tell the printEngine that rendering this canvas/page has failed.
14141422
// This will make the print proces stop.
1415-
obj.abort();
1423+
if ('abort' in object)
1424+
obj.abort();
1425+
else
1426+
obj.done();
1427+
self.pdfPage.destroy();
14161428
});
14171429
};
14181430
};

0 commit comments

Comments
 (0)