Open a PDF file and get a base64 data-URL of current page from canvas

Requirement: open a PDF file and get a base64 data-url from canvas,  so that the user can use it. 

Issue: While trying to use pdf.js to open PDF file of DBCS , it will draw pdf file on the canvas, Tried it with following JS: 

    const t = window.setInterval(()=>{        

            const pdfViewerApplication = this.PDFViewerApplication; 

            const pdfViewer = this.PDFViewerApplication.pdfViewer;        

            if(pdfViewer) {   

                        window.parent.pdfJSViewerReactive.pdf_app = pdfViewerApplication;   

                        window.clearInterval(t);     

                       pdfViewer.eventBus.on('pagerendered', (e)=>{

                                 window.parent.pdfJSViewerReactive.canvas = e.source.canvas;

                       }

            }

     } , 200)

Then canvas will be got from e.source.canvas, Even tried using blob and data-URL of the canvas.

Solution: The solution that I came across was since we have data coming from viewer.js , I write a module that capture these data from current page and trigger pdf ready event which let main screen can use these data.

pdfJ_Viewer_init.oml

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.