{"id":53570,"date":"2024-12-03T17:25:43","date_gmt":"2024-12-03T09:25:43","guid":{"rendered":"https:\/\/fwq.ai\/blog\/53570\/"},"modified":"2024-12-03T17:25:43","modified_gmt":"2024-12-03T09:25:43","slug":"%e6%89%93%e5%8d%b0%e8%a1%a8%e6%a0%bc%e6%a0%b7%e5%bc%8f%e5%81%8f%e5%b7%ae%e6%80%8e%e4%b9%88%e5%8a%9e%ef%bc%9f-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/53570\/","title":{"rendered":"\u6253\u5370\u8868\u683c\u6837\u5f0f\u504f\u5dee\u600e\u4e48\u529e\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>\u6253\u5370\u8868\u683c\u6837\u5f0f\u504f\u5dee\u600e\u4e48\u529e\uff1f <\/h1>\n<p><span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u4e0d\u77e5\u9053\u5927\u5bb6\u662f\u5426\u719f\u6089\uff1f\u4eca\u5929\u6211\u5c06\u7ed9\u5927\u5bb6\u4ecb\u7ecd<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u6253\u5370\u8868\u683c\u6837\u5f0f\u504f\u5dee\u600e\u4e48\u529e\uff1f \u300b<\/span>\uff0c\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u4f1a\u8bb2\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u4f60\u5728\u770b\u5b8c\u672c\u7bc7\u6587\u7ae0\u540e\uff0c\u6709\u66f4\u597d\u7684\u5efa\u8bae\u6216\u8005\u53d1\u73b0\u54ea\u91cc\u6709\u95ee\u9898\uff0c\u5e0c\u671b\u5927\u5bb6\u90fd\u80fd\u79ef\u6781\u8bc4\u8bba\u6307\u51fa\uff0c\u8c22\u8c22\uff01\u5e0c\u671b\u6211\u4eec\u80fd\u4e00\u8d77\u52a0\u6cb9\u8fdb\u6b65\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241202\/1733108438674d22d6dcba0.jpg\" class=\"aligncenter\" title=\"\u6253\u5370\u8868\u683c\u6837\u5f0f\u504f\u5dee\u600e\u4e48\u529e\uff1f\u63d2\u56fe\" alt=\"\u6253\u5370\u8868\u683c\u6837\u5f0f\u504f\u5dee\u600e\u4e48\u529e\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u6253\u5370\u65f6\u8868\u683c\u6837\u5f0f\u504f\u5dee\u7684\u5904\u7406\u65b9\u6cd5<\/strong><\/p>\n<p>\u5728\u6253\u5370\u8868\u683c\u65f6\uff0c\u4f60\u53ef\u80fd\u9047\u5230\u6253\u5370\u9884\u89c8\u548c\u5b9e\u9645\u6253\u5370\u7ed3\u679c\u4e4b\u95f4\u6837\u5f0f\u504f\u5dee\u7684\u95ee\u9898\u3002\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u4ee5\u4e0b\u662f\u4e00\u79cd\u5904\u7406\u65b9\u6cd5\uff1a<\/p>\n<p><strong>\u4f7f\u7528 DOM-to-Image \u6216 HTML2Canvas \u622a\u56fe<\/strong><\/p>\n<p>\u901a\u8fc7\u4f7f\u7528 dom-to-image \u6216 html2canvas \u7b49\u5e93\uff0c\u4f60\u53ef\u4ee5\u5bf9\u9875\u9762\u5185\u5bb9\u8fdb\u884c\u622a\u56fe\uff0c\u5e76\u5c06\u7ed3\u679c\u8f6c\u6362\u4e3a\u56fe\u50cf\u3002<\/p>\n<p><strong>\u6253\u5370\u56fe\u50cf<\/strong><\/p>\n<p>\u5c06\u9875\u9762\u5185\u5bb9\u622a\u56fe\u4e3a\u56fe\u50cf\u540e\uff0c\u4f60\u53ef\u4ee5\u5c06\u5176\u6253\u5370\u4e3a\u5e38\u89c4\u56fe\u50cf\u3002\u8fd9\u5c06\u786e\u4fdd\u56fe\u50cf\u4e2d\u7684\u6837\u5f0f\u5728\u6253\u5370\u65f6\u4fdd\u6301\u4e00\u81f4\u3002<\/p>\n<p><strong>\u5b9e\u65bd\u793a\u4f8b<\/strong><\/p>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u4f7f\u7528 dom-to-image \u5e93\u6253\u5370\u5e26\u6709\u8868\u683c\u7684\u7f51\u9875\u7684\u793a\u4f8b\uff1a<\/p>\n<pre>\/\/ \u5728 HTML \u4e2d\u5bfc\u5165 dom-to-image \u5e93\n&lt;script src=\"dom-to-image.min.js\"&gt;&lt;\/script&gt;\n\n\/\/ \u83b7\u53d6\u9700\u8981\u6253\u5370\u7684\u8868\u683c\u5143\u7d20\nconst table = document.getElementById('table');\n\n\/\/ \u5c06\u8868\u683c\u8f6c\u6362\u4e3a\u56fe\u50cf\ndomtoimage.toPng(table).then((dataUrl) =&gt; {\n  \/\/ \u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u56fe\u50cf\u5143\u7d20\n  const img = new Image();\n  img.src = dataUrl;\n\n  \/\/ \u5c06\u56fe\u50cf\u6dfb\u52a0\u5230\u9875\u9762\u4e2d\n  document.body.appendChild(img);\n\n  \/\/ \u6253\u5370\u56fe\u50cf\n  window.print();\n});<\/pre>\n<p>\u901a\u8fc7\u4f7f\u7528\u6b64\u65b9\u6cd5\uff0c\u4f60\u53ef\u4ee5\u5728\u6253\u5370\u65f6\u4fdd\u6301\u8868\u683c\u6837\u5f0f\u7684\u51c6\u786e\u6027\uff0c\u6d88\u9664\u6253\u5370\u9884\u89c8\u548c\u5b9e\u9645\u6253\u5370\u7ed3\u679c\u4e4b\u95f4\u7684\u504f\u5dee\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u672c\u6587\u7684\u5168\u90e8\u5185\u5bb9\u4e86\uff0c\u662f\u5426\u6709\u987a\u5229\u5e2e\u52a9\u4f60\u89e3\u51b3\u95ee\u9898\uff1f\u82e5\u662f\u80fd\u7ed9\u4f60\u5e26\u6765\u5b66\u4e60\u4e0a\u7684\u5e2e\u52a9\uff0c\u8bf7\u5927\u5bb6\u591a\u591a\u652f\u6301\u7c73\u4e91\uff01\u66f4\u591a\u5173\u4e8e\u6587\u7ae0\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u4e5f\u53ef\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\u3002<\/p>\n<dl>\n<dt><\/dt>\n<dd>\n   \u65b0\u786c\u76d8\u7535\u8111\u68c0\u6d4b\u4e0d\u5230\uff1f\n <\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>\u6253\u5370\u8868\u683c\u6837\u5f0f\u504f\u5dee\u600e\u4e48\u529e\uff1f \u6587\u7ae0\u4e0d\u77e5\u9053\u5927\u5bb6\u662f\u5426\u719f\u6089\uff1f\u4eca\u5929\u6211\u5c06\u7ed9\u5927\u5bb6\u4ecb\u7ecd\u300a\u6253\u5370\u8868\u683c\u6837\u5f0f\u504f\u5dee\u600e\u4e48\u529e\uff1f \u300b\uff0c\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u4f1a\u8bb2\u5230\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u4f60\u5728\u770b\u5b8c\u672c\u7bc7\u6587\u7ae0\u540e\uff0c\u6709\u66f4\u597d\u7684\u5efa\u8bae\u6216\u8005\u53d1\u73b0\u54ea\u91cc\u6709\u95ee\u9898\uff0c\u5e0c\u671b\u5927\u5bb6\u90fd\u80fd\u79ef\u6781\u8bc4\u8bba\u6307\u51fa\uff0c\u8c22\u8c22\uff01\u5e0c\u671b\u6211\u4eec\u80fd\u4e00\u8d77\u52a0\u6cb9\u8fdb\u6b65\uff01 \u6253\u5370\u65f6\u8868\u683c\u6837\u5f0f\u504f\u5dee\u7684\u5904\u7406\u65b9\u6cd5 \u5728\u6253\u5370\u8868\u683c\u65f6\uff0c\u4f60\u53ef\u80fd\u9047\u5230\u6253\u5370\u9884\u89c8\u548c\u5b9e\u9645\u6253\u5370\u7ed3\u679c\u4e4b\u95f4\u6837\u5f0f\u504f\u5dee\u7684\u95ee\u9898\u3002\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u4ee5\u4e0b\u662f\u4e00\u79cd\u5904\u7406\u65b9\u6cd5\uff1a \u4f7f\u7528 DOM-to-Image \u6216 HTML2Canvas \u622a\u56fe \u901a\u8fc7\u4f7f\u7528 dom-to-image \u6216 html2canvas \u7b49\u5e93\uff0c\u4f60\u53ef\u4ee5\u5bf9\u9875\u9762\u5185\u5bb9\u8fdb\u884c\u622a\u56fe\uff0c\u5e76\u5c06\u7ed3\u679c\u8f6c\u6362\u4e3a\u56fe\u50cf\u3002 \u6253\u5370\u56fe\u50cf \u5c06\u9875\u9762\u5185\u5bb9\u622a\u56fe\u4e3a\u56fe\u50cf\u540e\uff0c\u4f60\u53ef\u4ee5\u5c06\u5176\u6253\u5370\u4e3a\u5e38\u89c4\u56fe\u50cf\u3002\u8fd9\u5c06\u786e\u4fdd\u56fe\u50cf\u4e2d\u7684\u6837\u5f0f\u5728\u6253\u5370\u65f6\u4fdd\u6301\u4e00\u81f4\u3002 \u5b9e\u65bd\u793a\u4f8b \u4ee5\u4e0b\u662f\u4e00\u4e2a\u4f7f\u7528 dom-to-image \u5e93\u6253\u5370\u5e26\u6709\u8868\u683c\u7684\u7f51\u9875\u7684\u793a\u4f8b\uff1a \/\/ \u5728 HTML \u4e2d\u5bfc\u5165 dom-to-image \u5e93 &lt;script src=&#8221;dom-to-image.min.js&#8221;&gt;&lt;\/script&gt; \/\/ \u83b7\u53d6\u9700\u8981\u6253\u5370\u7684\u8868\u683c\u5143\u7d20 const table = document.getElementById(&#8216;table&#8217;); \/\/ \u5c06\u8868\u683c\u8f6c\u6362\u4e3a\u56fe\u50cf domtoimage.toPng(table).then((dataUrl) =&gt; { \/\/ \u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u56fe\u50cf\u5143\u7d20 const img = new Image(); img.src = dataUrl; \/\/ \u5c06\u56fe\u50cf\u6dfb\u52a0\u5230\u9875\u9762\u4e2d document.body.appendChild(img); \/\/ \u6253\u5370\u56fe\u50cf [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-53570","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/53570","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=53570"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/53570\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=53570"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=53570"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=53570"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}