var script document createElement script script type text javascript script src mozilla github io pdf js build pdf js document head appendChild script script onload function var pdfjsLib window pdfjs dist build pdf console log pdfjsLib console log version pdfjsLib version var loadingTask pdfjsLib getDocument url pdf console log loadingTask loadingTask end onload var script document createElement script script type text javascript script src mozilla github io pdf js build pdf js document head appendChild script let canvas document createElement canvas canvas id mycanvas canvas style width 200px canvas style height 250px canvas style border 1pt solid blue document body appendChild canvas If absolute URL from the remote server is provided configure the CORS header on that server var url https raw githubusercontent com mozilla pdf js ba2edeae web compressed tracemonkey pldi 09 pdf script onload function Loaded via script tag create shortcut to access PDF js exports var pdfjsLib window pdfjs dist build pdf The workerSrc property shall be specified pdfjsLib GlobalWorkerOptions workerSrc mozilla github io pdf js build pdf worker js Asynchronous download of PDF var loadingTask pdfjsLib getDocument url loadingTask promise then function pdf console log PDF loaded Fetch the first page var pageNumber 1 pdf getPage pageNumber then function page console log Page loaded var scale 1 5 var viewport page getViewport scale scale Prepare canvas using PDF page dimensions var canvas document getElementById mycanvas var context canvas getContext 2d canvas height viewport height canvas width viewport width Render PDF page into canvas context var renderContext canvasContext context viewport viewport var renderTask page render renderContext renderTask promise then function console log Page rendered function reason PDF loading error console error reason end onload var script document createElement script script type text javascript script src mozilla github io pdf js build pdf js document head appendChild script document body style height 400pt var url https raw githubusercontent com mozilla pdf js ba2edeae web compressed tracemonkey pldi 09 pdf script onload function Loaded via script tag create shortcut to access PDF js exports var pdfjsLib window pdfjs dist build pdf The workerSrc property shall be specified pdfjsLib GlobalWorkerOptions workerSrc mozilla github io pdf js build pdf worker js Asynchronous download of PDF var loadingTask pdfjsLib getDocument url loadingTask promise then function pdf console log PDF loaded console log Num pages pdf numPages Fetch each page and render it to a canvas for let pageNumber 1 pageNumber pdf numPages pageNumber pdf getPage pageNumber then function page console log Page loaded var scale 1 5 var viewport page getViewport scale scale Prepare canvas using PDF page dimensions let canvas document createElement canvas canvas style width 100pt canvas style height 130pt canvas width viewport width canvas height viewport height canvas style border 1pt solid blue document body appendChild canvas var context canvas getContext 2d Render PDF page into canvas context var renderContext canvasContext context viewport viewport var renderTask page render renderContext renderTask promise then function console log Page rendered end pdf getPage end for function reason console error reason PDF loading error end loadingTask promise onload
rContext renderTask promise then function console log Page rendered function reason PDF loading error console error reason end onload var script document createElement script script type text javascript script src mozilla github io pdf js build pdf js document head appendChild script document body style height 400pt var url https raw githubusercontent com mozilla pdf js ba2edeae web compressed tracemonkey pldi 09 pdf script onload function Loaded via script tag create shortcut to access PDF js exports var pdfjsLib window pdfjs dist build pdf The workerSrc property shall be specified pdfjsLib GlobalWorkerOptions workerSrc mozilla github io pdf js build pdf worker js Asynchronous download of PDF var loadingTask pdfjsLib getDocument url loadingTask promise then function pdf console log PDF loaded console log Num pages pdf numPages Fetch each page and render it to a canvas for let pageNumber 1 pageNumber pdf numPages pageNumber pdf getPage pageNumber then function page console log Page loaded var scale 1 5 var viewport page getViewport scale scale Prepare canvas using PDF page dimensions let canvas document createElement canvas canvas style width 100pt canvas style height 130pt canvas width viewport width canvas height viewport height canvas style border 1pt solid blue document body appendChild canvas var context canvas getContext 2d Render PDF page into canvas context var renderContext canvasContext context viewport viewport var renderTask page render renderContext renderTask promise then function console log Page rendered end pdf getPage end for function reason console error reason PDF loading error end loadingTask promise onload