{"id":1657,"date":"2026-02-01T16:43:56","date_gmt":"2026-02-01T08:43:56","guid":{"rendered":"https:\/\/www.52runoob.com\/?p=1657"},"modified":"2026-02-01T16:43:56","modified_gmt":"2026-02-01T08:43:56","slug":"pdf-js","status":"publish","type":"post","link":"https:\/\/www.52runoob.com\/index.php\/2026\/02\/01\/pdf-js\/","title":{"rendered":"pdf.js"},"content":{"rendered":"\n<p><strong>pdf.js<\/strong> \u662f\u4e2a\u597d\u4e1c\u897f \ud83d\udc4d<br>\u7b80\u5355\u8bf4\uff1a<strong>\u5b83\u8ba9\u6d4f\u89c8\u5668\u201c\u539f\u751f\u201d\u663e\u793a PDF\uff0c\u4e0d\u7528\u4efb\u4f55\u63d2\u4ef6<\/strong>\u3002\u4e0b\u9762\u6211\u7ed9\u4f60\u4e00\u4efd<strong>\u4ece\u539f\u7406 \u2192 \u7528\u6cd5 \u2192 \u672c\u5730\u90e8\u7f72 \u2192 \u4e8c\u6b21\u5f00\u53d1<\/strong>\u7684\u5b8c\u6574\u5b9e\u6218\u8bf4\u660e\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\u4e00\u3001pdf.js \u662f\u4ec0\u4e48\uff1f<\/h1>\n\n\n\n<p><strong>pdf.js<\/strong> \u662f <strong>Mozilla\uff08\u706b\u72d0\uff09\u5b98\u65b9\u5f00\u6e90\u9879\u76ee<\/strong>\uff1a<\/p>\n\n\n\n<p>\ud83d\udc49 \u7528 <strong>JavaScript + HTML5 Canvas<\/strong> \u5728\u6d4f\u89c8\u5668\u91cc\u89e3\u6790\u548c\u6e32\u67d3 PDF<br>\ud83d\udc49 \u4e0d\u4f9d\u8d56 Flash \/ \u63d2\u4ef6<br>\ud83d\udc49 \u652f\u6301 Chrome \/ Edge \/ Firefox \/ Safari<\/p>\n\n\n\n<p>GitHub \u9879\u76ee\uff1a<br><a href=\"https:\/\/github.com\/mozilla\/pdf.js\">https:\/\/github.com\/mozilla\/pdf.js<\/a><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\u4e8c\u3001pdf.js \u80fd\u5e72\u4ec0\u4e48\uff1f<\/h1>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\ud83c\udf10 \u7f51\u9875\u5185\u5d4c PDF \u9884\u89c8<\/li>\n\n\n\n<li>\ud83d\udcc4 \u5728\u7ebf\u9605\u8bfb\u5668\uff08\u7c7b\u4f3c\u6d4f\u89c8\u5668\u81ea\u5e26 PDF\uff09<\/li>\n\n\n\n<li>\ud83d\udd0d \u641c\u7d22 PDF \u6587\u672c<\/li>\n\n\n\n<li>\ud83d\udd0e \u7f29\u653e\u3001\u5206\u9875\u3001\u65cb\u8f6c<\/li>\n\n\n\n<li>\ud83d\udda8 \u6253\u5370<\/li>\n\n\n\n<li>\u270d\ufe0f \u6807\u6ce8\uff08\u90e8\u5206\u7248\u672c\uff09<\/li>\n\n\n\n<li>\ud83d\udcf1 \u79fb\u52a8\u7aef\u652f\u6301<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\u4e09\u3001\u6700\u7b80\u5355\u7684\u4f7f\u7528\u65b9\u5f0f\uff083 \u5206\u949f\u4e0a\u624b\uff09<\/h1>\n\n\n\n<h3 class=\"wp-block-heading\">\u65b9\u6cd5 1\uff1a\u76f4\u63a5\u7528\u5b98\u65b9 Viewer\uff08\u63a8\u8350\u65b0\u624b\uff09<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&amp;lt;iframe\n  src=&quot;https:\/\/mozilla.github.io\/pdf.js\/web\/viewer.html?file=demo.pdf&quot;\n  width=&quot;100%&quot;\n  height=&quot;800&quot;&gt;\n&amp;lt;\/iframe&gt;\n\n<\/pre><\/div>\n\n\n<p>\u53ea\u8981\u628a <code>demo.pdf<\/code> \u6362\u6210\u4f60\u7684 PDF \u8def\u5f84\u5373\u53ef\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\u65b9\u6cd5 2\uff1a\u672c\u5730\u90e8\u7f72 pdf.js\uff08\u6700\u5e38\u7528\uff09<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">1\ufe0f\u20e3 \u4e0b\u8f7d<\/h4>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\ngit clone https:\/\/github.com\/mozilla\/pdf.js.git\n\n<\/pre><\/div>\n\n\n<p>\u6216\u4e0b\u8f7d release \u5305\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">2\ufe0f\u20e3 \u4f7f\u7528 <code>web\/viewer.html<\/code><\/h4>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\npdfjs\/\n \u251c\u2500 web\/\n \u2502   \u251c\u2500 viewer.html\n \u2502   \u251c\u2500 viewer.js\n \u2502   \u2514\u2500 viewer.css\n \u251c\u2500 build\/\n\n<\/pre><\/div>\n\n\n<p>\u8bbf\u95ee\uff1a<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nhttp:\/\/localhost\/pdfjs\/web\/viewer.html?file=test.pdf\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\u56db\u3001\u524d\u7aef\u6700\u5c0f\u4ee3\u7801\u793a\u4f8b\uff08\u6838\u5fc3 API\uff09<\/h1>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&amp;lt;canvas id=&quot;pdf&quot;&gt;&amp;lt;\/canvas&gt;\n\n&amp;lt;script src=&quot;pdf.min.js&quot;&gt;&amp;lt;\/script&gt;\n&amp;lt;script&gt;\npdfjsLib.getDocument(&#039;test.pdf&#039;).promise.then(pdf =&gt; {\n  pdf.getPage(1).then(page =&gt; {\n    const scale = 1.5;\n    const viewport = page.getViewport({ scale });\n\n    const canvas = document.getElementById(&#039;pdf&#039;);\n    const ctx = canvas.getContext(&#039;2d&#039;);\n    canvas.width = viewport.width;\n    canvas.height = viewport.height;\n\n    page.render({\n      canvasContext: ctx,\n      viewport: viewport\n    });\n  });\n});\n&amp;lt;\/script&gt;\n\n<\/pre><\/div>\n\n\n<p>\ud83d\udc49 <strong>\u9002\u5408\u4e8c\u6b21\u5f00\u53d1\u3001\u81ea\u5b9a\u4e49 UI<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\u4e94\u3001\u5e38\u89c1\u529f\u80fd\u600e\u4e48\u5b9e\u73b0\uff1f<\/h1>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udcc4 \u7ffb\u9875<\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\npdf.getPage(pageNum)\n\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udd0d \u6587\u672c\u641c\u7d22<\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\npage.getTextContent()\n\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udd0e \u7f29\u653e<\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\npage.getViewport({ scale: 2 })\n\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udda8 \u6253\u5370<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u4f7f\u7528 viewer \u5185\u7f6e\u529f\u80fd<\/li>\n\n\n\n<li>\u6216\u8c03\u7528\u6d4f\u89c8\u5668\u6253\u5370<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\u516d\u3001pdf.js vs \u5176\u4ed6\u65b9\u6848<\/h1>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u65b9\u6848<\/th><th>\u4f18\u70b9<\/th><th>\u7f3a\u70b9<\/th><\/tr><\/thead><tbody><tr><td>pdf.js<\/td><td>\u514d\u8d39 \/ \u53ef\u63a7 \/ \u5f00\u6e90<\/td><td>\u590d\u6742 PDF \u6162<\/td><\/tr><tr><td>iframe + \u6d4f\u89c8\u5668<\/td><td>\u96f6\u4ee3\u7801<\/td><td>\u4e0d\u53ef\u63a7<\/td><\/tr><tr><td>\u5546\u4e1a SDK<\/td><td>\u529f\u80fd\u5f3a<\/td><td>\u8d35 \ud83d\udcb0<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\u4e03\u3001\u5e38\u89c1\u5751\uff08\u4f60\u5f88\u53ef\u80fd\u4f1a\u9047\u5230\uff09<\/h1>\n\n\n\n<h3 class=\"wp-block-heading\">\u2757 1. \u8de8\u57df\u95ee\u9898<\/h3>\n\n\n\n<p>PDF \u548c\u7f51\u9875\u5fc5\u987b\u540c\u6e90<br>\u6216\u670d\u52a1\u5668\u5f00\u542f CORS<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u2757 2. \u4e2d\u6587\u4e71\u7801\uff1f<\/h3>\n\n\n\n<p>pdf.js \u6ca1\u95ee\u9898<br>\ud83d\udc49 PDF \u672c\u8eab\u6ca1\u5d4c\u5165\u5b57\u4f53\u624d\u4f1a\u4e71\u7801<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u2757 3. \u5927\u6587\u4ef6\u6162<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5f00\u542f\u5206\u9875\u52a0\u8f7d<\/li>\n\n\n\n<li>\u964d\u4f4e scale<\/li>\n\n\n\n<li>\u7528 Web Worker\uff08\u9ed8\u8ba4\u5df2\u5f00\uff09<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\u516b\u3001\u9002\u5408\u54ea\u4e9b\u9879\u76ee\uff1f<\/h1>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5728\u7ebf\u6587\u6863\u7cfb\u7edf<\/li>\n\n\n\n<li>\u6559\u7a0b \/ \u8bf4\u660e\u4e66<\/li>\n\n\n\n<li>\u7f51\u76d8 \/ CMS<\/li>\n\n\n\n<li>\u5408\u540c\u9884\u89c8<\/li>\n\n\n\n<li>\u5b66\u4e60\u5e73\u53f0<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\u4e5d\u3001\u4f60\u73b0\u5728\u662f\u60f3\u201c\u7528\u201d\u8fd8\u662f\u201c\u6539\u201d pdf.js\uff1f<\/h1>\n\n\n\n<p>\u4f60\u53ef\u4ee5\u76f4\u63a5\u8bf4\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\ud83d\udc49\u300c\u6211\u53ea\u60f3\u7f51\u9875\u9884\u89c8 PDF\u300d<\/li>\n\n\n\n<li>\ud83d\udc49\u300c\u6211\u8981\u4e8c\u6b21\u5f00\u53d1 PDF \u9605\u8bfb\u5668\u300d<\/li>\n\n\n\n<li>\ud83d\udc49\u300cpdf.js + Vue \/ React\u300d<\/li>\n\n\n\n<li>\ud83d\udc49\u300c\u52a0\u6c34\u5370 \/ \u7981\u6b62\u4e0b\u8f7d\u300d<\/li>\n\n\n\n<li>\ud83d\udc49\u300c\u79fb\u52a8\u7aef\u9002\u914d\u300d<\/li>\n<\/ul>\n\n\n\n<p>\u6211\u53ef\u4ee5\u76f4\u63a5\u7ed9\u4f60\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u5b8c\u6574\u793a\u4f8b\u4ee3\u7801<\/strong><\/li>\n\n\n\n<li><strong>Vue \/ React \u7ec4\u4ef6\u5c01\u88c5<\/strong><\/li>\n\n\n\n<li><strong>\u6027\u80fd\u4f18\u5316\u65b9\u6848<\/strong><\/li>\n\n\n\n<li><strong>\u5b89\u5168\/\u9632\u4e0b\u8f7d\u601d\u8def<\/strong><\/li>\n<\/ul>\n\n\n\n<p>\u4e00\u53e5\u8bdd\uff1a<br><strong>pdf.js \u6211\u53ef\u4ee5\u5e26\u4f60\u4ece\u201c\u80fd\u7528\u201d\u5230\u201c\u4e13\u4e1a\u7ea7\u201d\ud83d\udcc4\ud83d\ude80<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>pdf.js \u662f\u4e2a\u597d\u4e1c\u897f \ud83d\udc4d\u7b80\u5355\u8bf4\uff1a\u5b83\u8ba9\u6d4f\u89c8\u5668\u201c\u539f\u751f\u201d\u663e\u793a PDF\uff0c\u4e0d\u7528\u4efb\u4f55\u63d2\u4ef6&#8230; <a class=\"more-link\" href=\"https:\/\/www.52runoob.com\/index.php\/2026\/02\/01\/pdf-js\/\">Continue Reading &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-1657","post","type-post","status-publish","format-standard","hentry","category-2"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/1657","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/comments?post=1657"}],"version-history":[{"count":1,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/1657\/revisions"}],"predecessor-version":[{"id":1658,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/1657\/revisions\/1658"}],"wp:attachment":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/media?parent=1657"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/categories?post=1657"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/tags?post=1657"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}