{"id":251,"date":"2023-07-05T15:21:58","date_gmt":"2023-07-05T07:21:58","guid":{"rendered":"https:\/\/support.fuxinsoft.cn\/?p=251"},"modified":"2025-10-28T11:40:43","modified_gmt":"2025-10-28T03:40:43","slug":"article-slug-158","status":"publish","type":"post","link":"https:\/\/support.fuxinsoft.cn\/?p=251","title":{"rendered":"\u5982\u4f55\u5728UI\u754c\u9762\u4e0a\u65b0\u589e\u4e0a\u4f20\u6309\u94ae\u5e76\u4fdd\u5b58\u6587\u4ef6\u5230\u670d\u52a1\u5668"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">1. \u5982\u4f55\u5728\u754c\u9762\u4e2d\u65b0\u589e\u201c\u4e0a\u4f20\u81f3\u670d\u52a1\u5668\u201d\u6309\u94ae\uff1f<\/h2>\n\n\n\n<p>\u53ef\u901a\u8fc7\u914d\u7f6e <code>fragments<\/code> \u6570\u7ec4\uff0c\u5728\u6307\u5b9a\u4f4d\u7f6e\u63d2\u5165\u81ea\u5b9a\u4e49\u4e0a\u4f20\u6309\u94ae\uff0c\u6838\u5fc3\u662f\u901a\u8fc7 <code>target<\/code> \u5b9a\u4f4d\u63d2\u5165\u4f4d\u7f6e\u3001<code>template<\/code> \u5b9a\u4e49\u6309\u94ae\u6837\u5f0f\uff0c\u5e76\u7ed1\u5b9a\u70b9\u51fb\u4e8b\u4ef6\u5904\u7406\u903b\u8f91\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u5b9e\u73b0\u6b65\u9aa4\uff1a<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u914d\u7f6e\u6309\u94ae\u63d2\u5165\u4f4d\u7f6e<\/strong>\uff1a\u901a\u8fc7 <code>target: \"download-file-button\"<\/code> \u6307\u5b9a\u5728\u201c\u4e0b\u8f7d\u6587\u4ef6\u201d\u6309\u94ae\u65c1\u63d2\u5165\uff0c<code>action: UIExtension.UIConsts.FRAGMENT_ACTION.AFTER<\/code> \u8868\u793a\u63d2\u5165\u5728\u76ee\u6807\u6309\u94ae\u4e4b\u540e\uff1b<\/li>\n\n\n\n<li><strong>\u5b9a\u4e49\u6309\u94ae\u6837\u5f0f<\/strong>\uff1a<code>template<\/code> \u4e2d\u4f7f\u7528 <code>ribbon-button<\/code> \u7ec4\u4ef6\uff0c\u8bbe\u7f6e\u56fe\u6807\uff08<code>icon-class<\/code>\uff09\u3001\u6587\u5b57\uff08<code>text<\/code>\uff09\u548c\u63d0\u793a\u4fe1\u606f\uff08<code>tooltip-title<\/code>\uff09\uff1b<\/li>\n\n\n\n<li><strong>\u7ed1\u5b9a\u70b9\u51fb\u4e8b\u4ef6<\/strong>\uff1a\u5728 <code>config<\/code> \u4e2d\u4e3a\u6309\u94ae\u7ed1\u5b9a\u56de\u8c03\u51fd\u6570\uff0c\u5b9e\u73b0\u6587\u4ef6\u83b7\u53d6\u4e0e\u4e0a\u4f20\u903b\u8f91\u3002<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">2. \u65b0\u589e\u4e0a\u4f20\u6309\u94ae\u7684\u5b8c\u6574\u793a\u4f8b\u4ee3\u7801\u662f\u4ec0\u4e48\uff1f<\/h2>\n\n\n\n<p>\u4ee5\u4e0b\u662f\u5728\u4e0b\u8f7d\u6309\u94ae\u540e\u65b0\u589e\u201c\u4e0a\u4f20\u81f3\u670d\u52a1\u5668\u201d\u6309\u94ae\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>fragments: &#91;\n  {\n    \/\/ \u65b0\u589e\u4e0a\u4f20\u6309\u94ae\u914d\u7f6e\n    target: \"download-file-button\", \/\/ \u63d2\u5165\u5230\u201c\u4e0b\u8f7d\u6587\u4ef6\u201d\u6309\u94ae\u65c1\n    action: UIExtension.UIConsts.FRAGMENT_ACTION.AFTER, \/\/ \u63d2\u5165\u5728\u76ee\u6807\u6309\u94ae\u4e4b\u540e\n    template:\n      '&lt;ribbon-button @tooltip tooltip-title=\"\u4e0a\u4f20\u81f3\u670d\u52a1\u5668\" name=\"upload-to-server-button\" icon-class=\"fv__icon-toolbar-download\" text=\"\u4e0a\u4f20\u81f3\u670d\u52a1\u5668\"&gt;&lt;\/ribbon-button&gt;',\n    config: &#91;\n      {\n        target: \"upload-to-server-button\", \/\/ \u7ed1\u5b9a\u65b0\u589e\u6309\u94ae\n        callback: function () {\n          \/\/ 8.1.0+\u7248\u672c\u63a8\u8350\u4f7f\u7528getFile\u63a5\u53e3\u83b7\u53d6\u6587\u4ef6\u5bf9\u8c61\n          this.getPDFUI()\n            .getPDFViewer()\n            .then((pdfViewer) =&gt; {\n              \/\/ \u83b7\u53d6\u5f53\u524dPDF\u6587\u6863\u7684\u6587\u4ef6\u5bf9\u8c61\uff0c\u5305\u542b\u6587\u4ef6\u540d\u7b49\u4fe1\u606f\n              return pdfViewer.currentPDFDoc.getFile({\n                flags: 0,\n                fileName: pdfViewer.currentPDFDoc.getFileName(),\n              });\n            })\n            .then((file) =&gt; {\n              \/\/ \u5904\u7406\u6587\u4ef6\uff08\u793a\u4f8b\u4e3a\u524d\u7aef\u4e0b\u8f7d\uff0c\u5b9e\u9645\u53ef\u66ff\u6362\u4e3a\u4e0a\u4f20\u81f3\u670d\u52a1\u5668\u903b\u8f91\uff09\n              console.info(\"\u6587\u4ef6\u4fe1\u606f\uff1a\", file);\n              const link = document.createElement(\"a\");\n              link.style.display = \"none\";\n              link.href = URL.createObjectURL(file); \/\/ \u521b\u5efa\u6587\u4ef6\u4e0b\u8f7d\u94fe\u63a5\n              link.setAttribute(\"download\", file.name); \/\/ \u6307\u5b9a\u4e0b\u8f7d\u6587\u4ef6\u540d\n              document.body.appendChild(link);\n              link.click(); \/\/ \u89e6\u53d1\u4e0b\u8f7d\n              document.body.removeChild(link);\n            });\n        },\n      },\n    ],\n  },\n]\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img fetchpriority=\"high\" decoding=\"async\" width=\"1024\" height=\"225\" src=\"https:\/\/support.fuxinsoft.cn\/wp-content\/uploads\/2023\/07\/image-1024x225.png\" alt=\"\" class=\"wp-image-7091\" srcset=\"https:\/\/support.fuxinsoft.cn\/wp-content\/uploads\/2023\/07\/image-1024x225.png 1024w, https:\/\/support.fuxinsoft.cn\/wp-content\/uploads\/2023\/07\/image-300x66.png 300w, https:\/\/support.fuxinsoft.cn\/wp-content\/uploads\/2023\/07\/image-768x169.png 768w, https:\/\/support.fuxinsoft.cn\/wp-content\/uploads\/2023\/07\/image.png 1059w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">\u4ee5\u4e0a\u56fe\u7247\u662f\u6dfb\u52a0\u6309\u94ae\u540e\u7684\u6548\u679c<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">3. \u4ee3\u7801\u4e2d <code>getFile<\/code> \u63a5\u53e3\u7684\u4f5c\u7528\u662f\u4ec0\u4e48\uff1f<\/h2>\n\n\n\n<p><code>getFile<\/code> \u662f\u798f\u6615PDF SDK 8.1.0\u53ca\u4ee5\u4e0a\u7248\u672c\u63d0\u4f9b\u7684\u63a5\u53e3\uff0c\u7528\u4e8e\u4fbf\u6377\u83b7\u53d6\u5f53\u524dPDF\u6587\u6863\u7684\u6587\u4ef6\u5bf9\u8c61\uff08<code>File<\/code> \u7c7b\u578b\uff09\uff0c\u5305\u542b\u6587\u6863\u5185\u5bb9\u3001\u6587\u4ef6\u540d\u7b49\u4fe1\u606f\uff0c\u76f8\u6bd4\u65e7\u7248 <code>getStream<\/code> \u63a5\u53e3\u66f4\u6613\u5904\u7406\uff08\u65e0\u9700\u624b\u52a8\u8f6c\u6362\u4e3a\u6587\u4ef6\u5bf9\u8c61\uff09\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u53c2\u6570\u8bf4\u660e\uff1a<code>flags: 0<\/code> \u8868\u793a\u9ed8\u8ba4\u914d\u7f6e\uff0c<code>fileName<\/code> \u7528\u4e8e\u6307\u5b9a\u6587\u4ef6\u540d\u79f0\uff08\u53ef\u4ece <code>currentPDFDoc.getFileName()<\/code> \u83b7\u53d6\u539f\u6587\u4ef6\u540d\uff09\uff1b<\/li>\n\n\n\n<li>\u8fd4\u56de\u503c\uff1a<code>Promise&lt;File&gt;<\/code>\uff0c resolved \u540e\u5f97\u5230\u53ef\u76f4\u63a5\u7528\u4e8e\u4e0a\u4f20\u6216\u4e0b\u8f7d\u7684\u6587\u4ef6\u5bf9\u8c61\u3002<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">4. \u5982\u4f55\u5c06\u6587\u4ef6\u4e0a\u4f20\u81f3\u670d\u52a1\u5668\uff08\u800c\u975e\u524d\u7aef\u4e0b\u8f7d\uff09\uff1f<\/h2>\n\n\n\n<p>\u793a\u4f8b\u4ee3\u7801\u4e2d\u201c\u524d\u7aef\u4e0b\u8f7d\u201d\u4ec5\u4e3a\u6f14\u793a\uff0c\u82e5\u9700\u4e0a\u4f20\u81f3\u670d\u52a1\u5668\uff0c\u53ef\u5728\u83b7\u53d6 <code>file<\/code> \u5bf9\u8c61\u540e\u66ff\u6362\u4e3a\u4e0a\u4f20\u903b\u8f91\uff0c\u793a\u4f8b\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>.then((file) =&gt; {\n  \/\/ \u66ff\u6362\u4e3a\u670d\u52a1\u5668\u4e0a\u4f20\u903b\u8f91\n  const formData = new FormData();\n  formData.append(\"pdfFile\", file); \/\/ \u5c06\u6587\u4ef6\u5bf9\u8c61\u6dfb\u52a0\u5230\u8868\u5355\n  \/\/ \u8c03\u7528\u670d\u52a1\u7aef\u4e0a\u4f20\u63a5\u53e3\n  fetch(\"\/api\/upload-pdf\", {\n    method: \"POST\",\n    body: formData,\n  })\n    .then((response) =&gt; {\n      if (response.ok) {\n        alert(\"\u4e0a\u4f20\u6210\u529f\");\n      } else {\n        alert(\"\u4e0a\u4f20\u5931\u8d25\");\n      }\n    })\n    .catch((error) =&gt; {\n      console.error(\"\u4e0a\u4f20\u51fa\u9519\uff1a\", error);\n      alert(\"\u7f51\u7edc\u5f02\u5e38\uff0c\u8bf7\u91cd\u8bd5\");\n    });\n});<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">5. \u6309\u94ae\u6837\u5f0f\u53ef\u4ee5\u81ea\u5b9a\u4e49\u5417\uff1f<\/h2>\n\n\n\n<p>\u53ef\u4ee5\u3002\u901a\u8fc7\u4fee\u6539 <code>template<\/code> \u4e2d\u7684 <code>ribbon-button<\/code> \u5c5e\u6027\u81ea\u5b9a\u4e49\u6837\u5f0f\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u56fe\u6807\uff1a\u4fee\u6539 <code>icon-class<\/code> \u66f4\u6362\u56fe\u6807\uff08\u5982\u4f7f\u7528\u5185\u7f6e\u56fe\u6807 <code>fv__icon-toolbar-upload<\/code> \u6216\u81ea\u5b9a\u4e49CSS\u7c7b\uff09\uff1b<\/li>\n\n\n\n<li>\u6587\u5b57\uff1a\u8c03\u6574 <code>text<\/code> \u5c5e\u6027\u4fee\u6539\u6309\u94ae\u663e\u793a\u6587\u672c\uff08\u5982\u6539\u4e3a\u201c\u4fdd\u5b58\u5230\u670d\u52a1\u5668\u201d\uff09\uff1b<\/li>\n\n\n\n<li>\u6837\u5f0f\uff1a\u901a\u8fc7\u6dfb\u52a0 <code>class<\/code> \u5c5e\u6027\u7ed1\u5b9a\u81ea\u5b9a\u4e49CSS\uff08\u5982 <code>class=\"custom-upload-btn\"<\/code>\uff09\uff0c\u518d\u901a\u8fc7CSS\u8c03\u6574\u989c\u8272\u3001\u5927\u5c0f\u7b49\u3002<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. \u5982\u4f55\u5728\u754c\u9762\u4e2d\u65b0\u589e\u201c\u4e0a\u4f20\u81f3\u670d\u52a1\u5668\u201d\u6309\u94ae\uff1f \u53ef\u901a\u8fc7\u914d\u7f6e fragments \u6570\u7ec4\uff0c\u5728\u6307\u5b9a\u4f4d\u7f6e\u63d2\u5165\u81ea\u5b9a\u4e49\u4e0a\u4f20\u6309 [&hellip;]<\/p>\n","protected":false},"author":26,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[67],"tags":[1138,1139,1137,1142,1140,1141,1143],"class_list":["post-251","post","type-post","status-publish","format-standard","hentry","category-websdk","tag-fragments","tag-getfile","tag-1137","tag-1142","tag-1140","tag-1141","tag-1143"],"pp_statuses_selecting_workflow":false,"pp_workflow_action":"current","pp_status_selection":"publish","_links":{"self":[{"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=\/wp\/v2\/posts\/251","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=\/wp\/v2\/users\/26"}],"replies":[{"embeddable":true,"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=251"}],"version-history":[{"count":5,"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=\/wp\/v2\/posts\/251\/revisions"}],"predecessor-version":[{"id":7132,"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=\/wp\/v2\/posts\/251\/revisions\/7132"}],"wp:attachment":[{"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=251"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=251"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=251"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}