Skip to content

Commit

Permalink
expose open method via postMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
qguv authored and mirhmousavi committed Mar 20, 2024
1 parent e8da59c commit 9195ff0
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions web/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,24 @@ function webViewerLoad() {
}
}
PDFViewerApplication.run(config);
window.addEventListener('message', handlePostMessage);
}

const postMessageHandlers = {
open(msg) {
const { pdfData } = msg;
PDFViewerApplication.open({ data: pdfData })
}
};

function handlePostMessage(event) {
const { type, msg } = event.data;
const handler = postMessageHandlers[type];
if (!handler) {
console.error(`pdf.js: no handler for postMessage with type ${type}`)
return;
}
return handler(msg);
}

// Block the "load" event until all pages are loaded, to ensure that printing
Expand Down

0 comments on commit 9195ff0

Please sign in to comment.