@@ -75,37 +75,30 @@ export default function(PDFJS) {
75
75
var PRINT_UNITS = PRINT_RESOLUTION / 72.0 ;
76
76
var CSS_UNITS = 96.0 / 72.0 ;
77
77
78
- var iframeElt = document . createElement ( 'iframe ' ) ;
78
+ var printContainerElement = document . createElement ( 'div ' ) ;
79
79
80
- function removeIframe ( ) {
81
-
82
- iframeElt . parentNode . removeChild ( iframeElt ) ;
80
+ function removePrintContainer ( ) {
81
+ printContainerElement . parentNode . removeChild ( printContainerElement ) ;
83
82
}
84
83
85
84
new Promise ( function ( resolve , reject ) {
86
-
87
- iframeElt . frameBorder = '0' ;
88
- iframeElt . scrolling = 'no' ;
89
- iframeElt . width = '0px;'
90
- iframeElt . height = '0px;'
91
- iframeElt . style . cssText = 'position: absolute; top: 0; left: 0' ;
92
-
93
- iframeElt . onload = function ( ) {
94
-
95
- resolve ( this . contentWindow ) ;
96
- }
97
-
98
- window . document . body . appendChild ( iframeElt ) ;
85
+ printContainerElement . frameBorder = '0' ;
86
+ printContainerElement . scrolling = 'no' ;
87
+ printContainerElement . width = '0px;'
88
+ printContainerElement . height = '0px;'
89
+ printContainerElement . style . cssText = 'position: absolute; top: 0; left: 0' ;
90
+
91
+ window . document . body . appendChild ( printContainerElement ) ;
92
+ resolve ( window )
99
93
} )
100
94
. then ( function ( win ) {
101
95
102
96
win . document . title = '' ;
103
97
104
98
return pdfDoc . getPage ( 1 )
105
99
. then ( function ( page ) {
106
-
107
100
var viewport = page . getViewport ( 1 ) ;
108
- win . document . head . appendChild ( win . document . createElement ( 'style' ) ) . textContent =
101
+ printContainerElement . appendChild ( win . document . createElement ( 'style' ) ) . textContent =
109
102
'@supports ((size:A4) and (size:1pt 1pt)) {' +
110
103
'@page { margin: 1pt; size: ' + ( ( viewport . width * PRINT_UNITS ) / CSS_UNITS ) + 'pt ' + ( ( viewport . height * PRINT_UNITS ) / CSS_UNITS ) + 'pt; }' +
111
104
'}' +
@@ -157,18 +150,16 @@ export default function(PDFJS) {
157
150
158
151
Promise . all ( allPages )
159
152
. then ( function ( ) {
160
-
161
153
win . focus ( ) ; // Required for IE
162
154
if ( win . document . queryCommandSupported ( 'print' ) ) {
163
155
win . document . execCommand ( 'print' , false , null ) ;
164
- } else {
156
+ } else {
165
157
win . print ( ) ;
166
- }
167
- removeIframe ( ) ;
158
+ }
159
+ removePrintContainer ( ) ;
168
160
} )
169
161
. catch ( function ( err ) {
170
-
171
- removeIframe ( ) ;
162
+ removePrintContainer ( ) ;
172
163
emitEvent ( 'error' , err ) ;
173
164
} )
174
165
} )
0 commit comments