@@ -14,16 +14,15 @@ const DEFAULTS = {
14
14
textLayer : ''
15
15
}
16
16
17
- const template = document . createElement ( 'template' )
18
- template . innerHTML = `
19
- <iframe frameborder="0" width="100%"></iframe>
20
- <style>:host{width:100%;display:block;overflow:hidden}:host iframe{height:100%}</style>
21
- `
22
-
23
17
export class PdfjsViewerElement extends HTMLElement {
24
18
constructor ( ) {
25
19
super ( )
26
20
const shadowRoot = this . attachShadow ( { mode : 'open' } )
21
+ const template = document . createElement ( 'template' )
22
+ template . innerHTML = `
23
+ <iframe frameborder="0" width="100%"></iframe>
24
+ <style>:host{width:100%;display:block;overflow:hidden}:host iframe{height:100%}</style>
25
+ `
27
26
shadowRoot . appendChild ( template . content . cloneNode ( true ) )
28
27
}
29
28
@@ -64,14 +63,15 @@ export class PdfjsViewerElement extends HTMLElement {
64
63
}
65
64
66
65
private renderViewer ( src : string ) {
67
- if ( ! src ) return
66
+ if ( ! src || ! this . iframe ) return
68
67
this . shadowRoot ! . replaceChild ( this . iframe . cloneNode ( ) , this . iframe )
69
68
this . iframe = this . shadowRoot ! . querySelector ( 'iframe' ) as PdfjsViewerElementIframe
70
- this . iframe . contentWindow . location . href = src
69
+ this . iframe . src = src
71
70
}
72
71
73
72
private setEventListeners ( ) {
74
73
document . addEventListener ( 'webviewerloaded' , ( ) => {
74
+ console . log ( this . iframe . contentWindow . PDFViewerApplication )
75
75
if ( this . getAttribute ( 'src' ) !== DEFAULTS . src ) this . iframe . contentWindow . PDFViewerApplicationOptions ?. set ( 'defaultUrl' , '' )
76
76
this . iframe . contentWindow . PDFViewerApplicationOptions ?. set ( 'disablePreferences' , true ) ;
77
77
this . iframe . contentWindow . PDFViewerApplicationOptions ?. set ( 'pdfBugEnabled' , true ) ;
@@ -91,6 +91,7 @@ declare global {
91
91
}
92
92
93
93
export interface PdfjsViewerElementIframeWindow extends Window {
94
+ PDFViewerApplication : any ,
94
95
PDFViewerApplicationOptions : {
95
96
set : ( name : string , value : string | boolean ) => void
96
97
}
0 commit comments