TypeScript: pdf.js v4.0.379
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | <!doctype html> <html> <head> <meta charset= "utf-8" > <meta http-equiv= "X-UA-Compatible" content= "chrome=1" > <meta name= "viewport" content= "width=device-width, initial-scale=1, maximum-scale=1" > <title>pdf v4.0.379 </title> <meta name= "Keywords" content= "涂聚文,塗聚文,捷為工作室,万年历,万年历查询,黄历,黄历查询,塗聚文,捷為工作室" /> <meta name= "Description" content= "塗聚文,捷為工作室,信息流,物流,人力资源流,资本流的系统解决方案的开发与设计. " /> <meta name= "author" content= "geovindu,塗聚文,涂聚文,Geovin Du" /> <script src= "../build/pdf.mjs" type= "module" ></script> <link rel= "stylesheet" href= "viewer.css" > <script src= "../build/pdf.mjs" type= "module" ></script> <script type= "module" > // If absolute URL from the remote server is provided, configure the CORS // header on that server. var url = 'http://www.dusystem.com/PDFjs/4.0/web/123.pdf' ; // Loaded via <script> tag, create shortcut to access PDF.js exports. var { pdfjsLib } = globalThis; // The workerSrc property shall be specified. pdfjsLib.GlobalWorkerOptions.workerSrc = '../build/pdf.worker.mjs' ; var pdfDoc = null , pageNum = 1, pageRendering = false , pageNumPending = null , scale = 0.8, canvas = document.getElementById( 'the-canvas' ), ctx = canvas.getContext( '2d' ); /** * Get page info from document, resize canvas accordingly, and render page. * @param num Page number. */ function renderPage(num) { pageRendering = true ; // Using promise to fetch the page pdfDoc.getPage(num).then(function(page) { var viewport = page.getViewport({scale: scale}); canvas.height = viewport.height; canvas.width = viewport.width; // Render PDF page into canvas context var renderContext = { canvasContext: ctx, viewport: viewport }; var renderTask = page.render(renderContext); // Wait for rendering to finish renderTask.promise.then(function() { pageRendering = false ; if (pageNumPending !== null ) { // New page rendering is pending renderPage(pageNumPending); pageNumPending = null ; } }); }); // Update page counters document.getElementById( 'page_num' ).textContent = num; } /** * If another page rendering in progress, waits until the rendering is * finised. Otherwise, executes rendering immediately. */ function queueRenderPage(num) { if (pageRendering) { pageNumPending = num; } else { renderPage(num); } } /** * Displays previous page. */ function onPrevPage() { if (pageNum <= 1) { return ; } pageNum--; queueRenderPage(pageNum); } document.getElementById( 'prev' ).addEventListener( 'click' , onPrevPage); /** * Displays next page. */ function onNextPage() { if (pageNum >= pdfDoc.numPages) { return ; } pageNum++; queueRenderPage(pageNum); } document.getElementById( 'next' ).addEventListener( 'click' , onNextPage); /** * Asynchronously downloads PDF. */ pdfjsLib.getDocument(url).promise.then(function(pdfDoc_) { pdfDoc = pdfDoc_; document.getElementById( 'page_count' ).textContent = pdfDoc.numPages; // Initial/first page rendering renderPage(pageNum); }); </script> <style type= "text/css" > #the-canvas { border: 1px solid black; direction: ltr; } </style> </head> <body> <h1>PDF.js Previous/Next example</h1> <p>Please use <a href= "https://mozilla.github.io/pdf.js/getting_started/#download" ><i>official releases</i></a> in production environments.</p> <div> <button id= "prev" >Previous</button> <button id= "next" >Next</button> <span>Page: <span id= "page_num" ></span> / <span id= "page_count" ></span></span> </div> <canvas id= "the-canvas" ></canvas> </body> </html> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | <!doctype html> <html> <head> <meta charset= "utf-8" > <meta http-equiv= "X-UA-Compatible" content= "chrome=1" > <meta name= "viewport" content= "width=device-width, initial-scale=1, maximum-scale=1" > <title>pdf using base64 encoded PDF</title> <meta name= "Keywords" content= "涂聚文,塗聚文,捷為工作室,万年历,万年历查询,黄历,黄历查询,塗聚文,捷為工作室" /> <meta name= "Description" content= "塗聚文,捷為工作室,信息流,物流,人力资源流,资本流的系统解决方案的开发与设计. " /> <meta name= "author" content= "geovindu,塗聚文,涂聚文,Geovin Du" /> <script src= "../build/pdf.mjs" type= "module" ></script> <link rel= "stylesheet" href= "viewer.css" > <script type= "module" > // atob() is used to convert base64 encoded PDF to binary-like data. // (See also https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/ // Base64_encoding_and_decoding.) var pdfData = atob( 'JVBERi0xLjcKCjEgMCBvYmogICUgZW50cnkgcG9pbnQKPDwKICAvVHlwZSAvQ2F0YWxvZwog' + 'IC9QYWdlcyAyIDAgUgo+PgplbmRvYmoKCjIgMCBvYmoKPDwKICAvVHlwZSAvUGFnZXMKICAv' + 'TWVkaWFCb3ggWyAwIDAgMjAwIDIwMCBdCiAgL0NvdW50IDEKICAvS2lkcyBbIDMgMCBSIF0K' + 'Pj4KZW5kb2JqCgozIDAgb2JqCjw8CiAgL1R5cGUgL1BhZ2UKICAvUGFyZW50IDIgMCBSCiAg' + 'L1Jlc291cmNlcyA8PAogICAgL0ZvbnQgPDwKICAgICAgL0YxIDQgMCBSIAogICAgPj4KICA+' + 'PgogIC9Db250ZW50cyA1IDAgUgo+PgplbmRvYmoKCjQgMCBvYmoKPDwKICAvVHlwZSAvRm9u' + 'dAogIC9TdWJ0eXBlIC9UeXBlMQogIC9CYXNlRm9udCAvVGltZXMtUm9tYW4KPj4KZW5kb2Jq' + 'Cgo1IDAgb2JqICAlIHBhZ2UgY29udGVudAo8PAogIC9MZW5ndGggNDQKPj4Kc3RyZWFtCkJU' + 'CjcwIDUwIFRECi9GMSAxMiBUZgooSGVsbG8sIHdvcmxkISkgVGoKRVQKZW5kc3RyZWFtCmVu' + 'ZG9iagoKeHJlZgowIDYKMDAwMDAwMDAwMCA2NTUzNSBmIAowMDAwMDAwMDEwIDAwMDAwIG4g' + 'CjAwMDAwMDAwNzkgMDAwMDAgbiAKMDAwMDAwMDE3MyAwMDAwMCBuIAowMDAwMDAwMzAxIDAw' + 'MDAwIG4gCjAwMDAwMDAzODAgMDAwMDAgbiAKdHJhaWxlcgo8PAogIC9TaXplIDYKICAvUm9v' + 'dCAxIDAgUgo+PgpzdGFydHhyZWYKNDkyCiUlRU9G' ); // Loaded via <script> tag, create shortcut to access PDF.js exports. var { pdfjsLib } = globalThis; // The workerSrc property shall be specified. pdfjsLib.GlobalWorkerOptions.workerSrc = '../build/pdf.worker.mjs' ; // Using DocumentInitParameters object to load binary data. var loadingTask = pdfjsLib.getDocument({data: pdfData}); 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( 'the-canvas' ); 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); }); </script> <style type= "text/css" > #the-canvas { border: 1px solid black; direction: ltr; } </style> </head> <body> <h1>PDF.js 'Hello, base64!' example</h1> <p>Please use <a href= "https://mozilla.github.io/pdf.js/getting_started/#download" ><i>official releases</i></a> in production environments.</p> <canvas id= "the-canvas" ></canvas> </body> </html> |
https://github.com/dealfonso/pdfjs-viewer
https://mozilla.github.io/pdf.js/getting_started
https://mozilla.github.io/pdf.js/getting_started
https://mozilla.github.io/pdf.js/examples/
https://mozilla.github.io/pdf.js/examples/index.html#interactive-examples
哲学管理(学)人生, 文学艺术生活, 自动(计算机学)物理(学)工作, 生物(学)化学逆境, 历史(学)测绘(学)时间, 经济(学)数学金钱(理财), 心理(学)医学情绪, 诗词美容情感, 美学建筑(学)家园, 解构建构(分析)整合学习, 智商情商(IQ、EQ)运筹(学)生存.---Geovin Du(涂聚文)
分类:
Ajax&JavaScript
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
2022-04-07 TypeScript: miniProgram 获取用户信息