@@ -127,7 +127,7 @@ const addEventListener = (el, pdfViewer, eventBus, invoke, options) => {
127127 }
128128
129129 if ( options . triggerPagesInit === true ) {
130- await invoke . invokeMethodAsync ( "pagesInit " , numPages ) ;
130+ await invoke . invokeMethodAsync ( "PagesInit " , numPages ) ;
131131 }
132132 } ) ;
133133
@@ -139,6 +139,12 @@ const addEventListener = (el, pdfViewer, eventBus, invoke, options) => {
139139 if ( options . triggerPagesLoaded === true ) {
140140 await invoke . invokeMethodAsync ( "PagesLoaded" , e . pagesCount ) ;
141141 }
142+
143+ const controls = el . querySelector ( ".bb-view-controls" ) ;
144+ EventHandler . on ( controls , "click" , ".bb-view-print" , e => {
145+ printPdf ( options . url ) ;
146+ await invoke . invokeMethodAsync ( "Printing" ) ;
147+ } ) ;
142148 } )
143149
144150 eventBus . on ( "pagechanging" , async evt => {
@@ -276,6 +282,31 @@ const makeThumb = async page => {
276282 return canvas ;
277283}
278284
285+ const printPdf = url => {
286+ let iframe = document . querySelector ( ".bb-view-print-iframe" ) ;
287+ if ( iframe ) {
288+ iframe . remove ( ) ;
289+ }
290+
291+ iframe = document . createElement ( "iframe" ) ;
292+ iframe . classList = "bb-view-print-iframe" ;
293+ iframe . style . position = "fixed" ;
294+ iframe . style . right = "100%" ;
295+ iframe . style . bottom = "100%" ;
296+ iframe . src = url ;
297+
298+ iframe . onload = ( ) => {
299+ iframe . contentWindow . addEventListener ( 'afterprint' , function ( ) {
300+ document . body . removeChild ( iframe ) ;
301+ } ) ;
302+
303+ iframe . contentWindow . focus ( ) ;
304+ iframe . contentWindow . print ( ) ;
305+ } ;
306+
307+ document . body . appendChild ( iframe ) ;
308+ }
309+
279310export function dispose ( id ) {
280311 Data . remove ( id ) ;
281312
@@ -304,5 +335,13 @@ export function dispose(id) {
304335 if ( thumbnailsContainer ) {
305336 EventHandler . off ( thumbnailsContainer , "click" ) ;
306337 }
338+
339+ const controls = el . querySelector ( ".bb-view-controls" ) ;
340+ EventHandler . off ( controls , "click" ) ;
341+
342+ const iframe = document . querySelector ( '.bb-view-print-iframe' ) ;
343+ if ( iframe ) {
344+ iframe . remove ( ) ;
345+ }
307346 }
308347}
0 commit comments