[SalesForce] Trying to show PDF in Lightning web component in iFrame but it does not render the PDF file

I am trying to display a pdf file using Base64data in the Lightning Web component, the PDF Viewer renders but it does not get the PDF file in it.

here's my HTML:

<template if:true={showModal}>
        <c-modal show-modal={showModal} is-large="true" onclosemodal={handleCloseModal}>
            <iframe id="pdfFrame" src="/resource/pdfjs/web/viewer.html" width="100%" height="600" class="pdfFrame" onload={loadpdf}></iframe>
        </c-modal>
</template>

Here's my JS controller to load PDF :

loadpdf(event){
        alert(this.pdfData);
        this.template.querySelector('pdfFrame').contentWindow.postMessage(this.pdfData,'*');    
    }

in LoadPdf alert statement, the pdf data is coming just fine, the pdf viewer also renders fine like below but without the actual file :

enter image description here

is the code to postMessage in iFrame correct here?

Using this GitHub library.

Best Answer

solved this by making a change in the postmessage. Here's what I updated :

this.template.querySelector('iframe').contentWindow.postMessage(this.pdfData, window.location.origin);

I hope this helps someone load pdf in lwc.