import { Layout } from './Layout' ; import { GlobalWorkerOptions , PDFDocumentProxy , getDocument , version } from 'pdfjs-dist' ; const pdfWorkerSrc = `https://cdnjs.cloudflare.com/ajax/libs/pdf.js/${ version }/pdf.worker.min.js` ; GlobalWorkerOptions . workerSrc = pdfWorkerSrc ; export class PDFDocument { pdfDoc : PDFDocumentProxy = null ; dataURL : string = undefined ; /**
     * Asynchronously downloads PDF.
     * The promise is resolved when the PDF is loaded
     */ open ( url ) { this . dataURL = url ; return new Promise ( ( resolve ) => { getDocument ( url ) . promise . then ( ( pdfDoc_ ) => { this . pdfDoc = pdfDoc_ ; resolve ( ) ; } ) ; } ) ; } param num returns getCanvasPage ( num ) { return new Promise ( ( resolve ) => { const canvas = document . createElement ( "canvas" ) ; canvas . classList . add ( "pdfPage" ) ; const ctx = canvas . getContext ( "2d" ) ; this . pdfDoc . getPage ( num ) . then ( ( page ) => { const w = page . getViewport ( { scale : 1.0 } ) . width ; const h = page . getViewport ( { scale : 1.0 } ) . height ; const scale = ( w / h > Layout . getWindowWidth ( ) / Layout . getWindowHeight ( ) ) ? Layout . getWindowWidth ( ) / w : Layout . getWindowHeight ( ) / h ; const viewport = page . getViewport ( { scale : scale } ) ; canvas . height = viewport . height ; canvas . width = viewport . width ; /**const x = (w/h  > Layout.getWindowWidth() /Layout.getWindowHeight()) ? 0 : (Layout.getWindowWidth() - (canvas.width)) / 2;
    
                const y = (w/h  > Layout.getWindowWidth() /Layout.getWindowHeight()) ? (Layout.getWindowHeight() - (canvas.height)) / 2 : 0;*/ const renderContext = { canvasContext : ctx , viewport : viewport } ; const renderTask = page . render ( renderContext ) ; renderTask . promise . then ( ( ) => { resolve ( canvas ) ; } ) ; } ) ; } ) ; } returns get nbPages ( ) : number { return this . pdfDoc . numPages ; } }