@@ -14,16 +14,15 @@ const DEFAULTS = {
1414 textLayer : ''
1515}
1616
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-
2317export class PdfjsViewerElement extends HTMLElement {
2418 constructor ( ) {
2519 super ( )
2620 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+ `
2726 shadowRoot . appendChild ( template . content . cloneNode ( true ) )
2827 }
2928
@@ -64,14 +63,15 @@ export class PdfjsViewerElement extends HTMLElement {
6463 }
6564
6665 private renderViewer ( src : string ) {
67- if ( ! src ) return
66+ if ( ! src || ! this . iframe ) return
6867 this . shadowRoot ! . replaceChild ( this . iframe . cloneNode ( ) , this . iframe )
6968 this . iframe = this . shadowRoot ! . querySelector ( 'iframe' ) as PdfjsViewerElementIframe
70- this . iframe . contentWindow . location . href = src
69+ this . iframe . src = src
7170 }
7271
7372 private setEventListeners ( ) {
7473 document . addEventListener ( 'webviewerloaded' , ( ) => {
74+ console . log ( this . iframe . contentWindow . PDFViewerApplication )
7575 if ( this . getAttribute ( 'src' ) !== DEFAULTS . src ) this . iframe . contentWindow . PDFViewerApplicationOptions ?. set ( 'defaultUrl' , '' )
7676 this . iframe . contentWindow . PDFViewerApplicationOptions ?. set ( 'disablePreferences' , true ) ;
7777 this . iframe . contentWindow . PDFViewerApplicationOptions ?. set ( 'pdfBugEnabled' , true ) ;
@@ -91,6 +91,7 @@ declare global {
9191}
9292
9393export interface PdfjsViewerElementIframeWindow extends Window {
94+ PDFViewerApplication : any ,
9495 PDFViewerApplicationOptions : {
9596 set : ( name : string , value : string | boolean ) => void
9697 }
0 commit comments