{"id":52341,"date":"2024-12-03T10:46:56","date_gmt":"2024-12-03T02:46:56","guid":{"rendered":"https:\/\/fwq.ai\/blog\/52341\/"},"modified":"2024-12-03T10:46:56","modified_gmt":"2024-12-03T02:46:56","slug":"%e7%a7%bb%e5%8a%a8%e7%ab%af%e4%b8%8b%e8%bd%bd-linux-%e6%a0%b9%e7%9b%ae%e5%bd%95%e4%b8%8b%e7%9a%84-pdf-%e6%96%87%e4%bb%b6%ef%bc%8c%e4%b8%ba%e4%bd%95%e4%bc%9a%e6%98%be%e7%a4%ba%e6%9c%aa%e7%9f%a5","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/52341\/","title":{"rendered":"\u79fb\u52a8\u7aef\u4e0b\u8f7d Linux \u6839\u76ee\u5f55\u4e0b\u7684 PDF \u6587\u4ef6\uff0c\u4e3a\u4f55\u4f1a\u663e\u793a\u672a\u77e5\u6587\u4ef6\uff1f\u5982\u4f55\u89e3\u51b3\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>\u79fb\u52a8\u7aef\u4e0b\u8f7d Linux \u6839\u76ee\u5f55\u4e0b\u7684 PDF \u6587\u4ef6\uff0c\u4e3a\u4f55\u4f1a\u663e\u793a\u672a\u77e5\u6587\u4ef6\uff1f\u5982\u4f55\u89e3\u51b3\uff1f<\/h1>\n<p>\u4ece\u73b0\u5728\u5f00\u59cb\uff0c\u52aa\u529b\u5b66\u4e60\u5427\uff01\u672c\u6587<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u79fb\u52a8\u7aef\u4e0b\u8f7d Linux \u6839\u76ee\u5f55\u4e0b\u7684 PDF \u6587\u4ef6\uff0c\u4e3a\u4f55\u4f1a\u663e\u793a\u672a\u77e5\u6587\u4ef6\uff1f\u5982\u4f55\u89e3\u51b3\uff1f\u300b<\/span>\u4e3b\u8981\u8bb2\u89e3\u4e86<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u76f8\u5173\u77e5\u8bc6\u70b9\uff0c\u6211\u4f1a\u5728\u7c73\u4e91\u4e2d\u6301\u7eed\u66f4\u65b0\u76f8\u5173\u7684\u7cfb\u5217\u6587\u7ae0\uff0c\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u5e76\u79ef\u6781\u7559\u8a00\u5efa\u8bae\u3002\u4e0b\u9762\u5c31\u5148\u4e00\u8d77\u6765\u770b\u4e00\u4e0b\u672c\u7bc7\u6b63\u6587\u5185\u5bb9\u5427\uff0c\u5e0c\u671b\u80fd\u5e2e\u5230\u4f60\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241120\/1732067839673d41ff0eeef.jpg\" class=\"aligncenter\" title=\"\u79fb\u52a8\u7aef\u4e0b\u8f7d Linux \u6839\u76ee\u5f55\u4e0b\u7684 PDF \u6587\u4ef6\uff0c\u4e3a\u4f55\u4f1a\u663e\u793a\u672a\u77e5\u6587\u4ef6\uff1f\u5982\u4f55\u89e3\u51b3\uff1f\u63d2\u56fe\" alt=\"\u79fb\u52a8\u7aef\u4e0b\u8f7d Linux \u6839\u76ee\u5f55\u4e0b\u7684 PDF \u6587\u4ef6\uff0c\u4e3a\u4f55\u4f1a\u663e\u793a\u672a\u77e5\u6587\u4ef6\uff1f\u5982\u4f55\u89e3\u51b3\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5728\u79fb\u52a8\u7aef\u4e0b\u8f7d pdf \u6587\u4ef6<\/strong><\/p>\n<p><strong>\u95ee\u9898\u63cf\u8ff0<\/strong><\/p>\n<p>\u5f00\u53d1\u8005\u5e0c\u671b\u5728\u79fb\u52a8\u7aef\u4e0b\u8f7d\u5b58\u50a8\u5728 linux \u6839\u76ee\u5f55\u4e0b\u7684 pdf \u6587\u4ef6\uff0c\u4f46\u4f7f\u7528 servlet \u8fd4\u56de\u6587\u4ef6\u6d41\u540e\uff0c\u53d1\u73b0\u79fb\u52a8\u7aef\u70b9\u51fb\u4e0b\u8f7d\u540e\u663e\u793a\u672a\u77e5\u6587\u4ef6\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6cd5<\/strong><\/p>\n<p><strong>\u7f16\u7801\u6587\u4ef6\u8def\u5f84<\/strong><\/p>\n<p>\u7f16\u7801\u6587\u4ef6\u8def\u5f84\u53ef\u4ee5\u89e3\u51b3\u79fb\u52a8\u7aef\u65e0\u6cd5\u6b63\u786e\u8bc6\u522b\u8def\u5f84\u7684\u95ee\u9898\u3002\u5728 servlet \u4e2d\u83b7\u53d6\u6587\u4ef6\u8def\u5f84\u65f6\uff0c\u4f7f\u7528 encodeuricomponent(path) \u5bf9\u8def\u5f84\u8fdb\u884c\u7f16\u7801\uff0c\u7136\u540e\u518d\u53d1\u9001\u7ed9\u5ba2\u6237\u7aef\u3002<\/p>\n<p>\u4fee\u6539\u540e\u7684 pdfdownloadservlet \u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>resp.setcontenttype(\"application\/pdf;charset=utf-8\");\nresp.setheader(\"content-disposition\", \"attachment;filename=a.pdf\");\nstring path = req.getparameter(\"path\");\nfile w2 = new file(path);\nlogger.info(\"pdf path:\" + w2.getpath());\n\nfileinputstream fs;\ntry {\n    fs = new fileinputstream(w2);\n    bufferedinputstream bs = new bufferedinputstream(fs);\n    printwriter outw = resp.getwriter();\n    byte buffbytes[] = new byte[3072];\n    int read = 0;\n    while ((read = bs.read(buffbytes)) != -1) {\n        string strtemp = new sun.misc.base64encoder().encode(arrays.copyofrange(buffbytes, 0, read));\n        outw.print(strtemp);\n    }\n} catch (exception e) {\n    logger.info(\"pdf\u51fa\u9519\");\n    logger.error(e.getmessage(), e);\n}<\/pre>\n<p>\u4fee\u6539\u540e\u7684 javascript \u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>$.ajax({\n  type: \"post\",\n  async: false,\n  url: projectName + \"\/PdfDownloadServlet?path=\" + encodeURIComponent(path),\n  success: function (data) {\n    var blob = new Blob([data], { type: \"application\/pdf;charset=utf-8\" });\n    saveAs(blob, \"CF1002.pdf\");\n  },\n  error: function (e) {\n    console.log(e);\n    alert(e);\n  },\n});<\/pre>\n<p>\u901a\u8fc7\u5bf9\u6587\u4ef6\u8def\u5f84\u8fdb\u884c\u7f16\u7801\uff0c\u79fb\u52a8\u7aef\u5373\u53ef\u6b63\u786e\u8bc6\u522b\u8def\u5f84\uff0c\u5e76\u4e0b\u8f7d pdf \u6587\u4ef6\u3002<\/p>\n<p>\u597d\u4e86\uff0c\u672c\u6587\u5230\u6b64\u7ed3\u675f\uff0c\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u300a\u79fb\u52a8\u7aef\u4e0b\u8f7d Linux \u6839\u76ee\u5f55\u4e0b\u7684 PDF \u6587\u4ef6\uff0c\u4e3a\u4f55\u4f1a\u663e\u793a\u672a\u77e5\u6587\u4ef6\uff1f\u5982\u4f55\u89e3\u51b3\uff1f\u300b\uff0c\u5e0c\u671b\u672c\u6587\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff01\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff0c\u7ed9\u5927\u5bb6\u5206\u4eab\u66f4\u591a\u6587\u7ae0\u77e5\u8bc6\uff01<\/p>\n<dl>\n<dt><\/dt>\n<dd>\n   gpw\u73a9lol\u597d\u7528\u5417\uff1f\n <\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>\u79fb\u52a8\u7aef\u4e0b\u8f7d Linux \u6839\u76ee\u5f55\u4e0b\u7684 PDF \u6587\u4ef6\uff0c\u4e3a\u4f55\u4f1a\u663e\u793a\u672a\u77e5\u6587\u4ef6\uff1f\u5982\u4f55\u89e3\u51b3\uff1f \u4ece\u73b0\u5728\u5f00\u59cb\uff0c\u52aa\u529b\u5b66\u4e60\u5427\uff01\u672c\u6587\u300a\u79fb\u52a8\u7aef\u4e0b\u8f7d Linux \u6839\u76ee\u5f55\u4e0b\u7684 PDF \u6587\u4ef6\uff0c\u4e3a\u4f55\u4f1a\u663e\u793a\u672a\u77e5\u6587\u4ef6\uff1f\u5982\u4f55\u89e3\u51b3\uff1f\u300b\u4e3b\u8981\u8bb2\u89e3\u4e86\u7b49\u7b49\u76f8\u5173\u77e5\u8bc6\u70b9\uff0c\u6211\u4f1a\u5728\u7c73\u4e91\u4e2d\u6301\u7eed\u66f4\u65b0\u76f8\u5173\u7684\u7cfb\u5217\u6587\u7ae0\uff0c\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u5e76\u79ef\u6781\u7559\u8a00\u5efa\u8bae\u3002\u4e0b\u9762\u5c31\u5148\u4e00\u8d77\u6765\u770b\u4e00\u4e0b\u672c\u7bc7\u6b63\u6587\u5185\u5bb9\u5427\uff0c\u5e0c\u671b\u80fd\u5e2e\u5230\u4f60\uff01 \u5728\u79fb\u52a8\u7aef\u4e0b\u8f7d pdf \u6587\u4ef6 \u95ee\u9898\u63cf\u8ff0 \u5f00\u53d1\u8005\u5e0c\u671b\u5728\u79fb\u52a8\u7aef\u4e0b\u8f7d\u5b58\u50a8\u5728 linux \u6839\u76ee\u5f55\u4e0b\u7684 pdf \u6587\u4ef6\uff0c\u4f46\u4f7f\u7528 servlet \u8fd4\u56de\u6587\u4ef6\u6d41\u540e\uff0c\u53d1\u73b0\u79fb\u52a8\u7aef\u70b9\u51fb\u4e0b\u8f7d\u540e\u663e\u793a\u672a\u77e5\u6587\u4ef6\u3002 \u89e3\u51b3\u65b9\u6cd5 \u7f16\u7801\u6587\u4ef6\u8def\u5f84 \u7f16\u7801\u6587\u4ef6\u8def\u5f84\u53ef\u4ee5\u89e3\u51b3\u79fb\u52a8\u7aef\u65e0\u6cd5\u6b63\u786e\u8bc6\u522b\u8def\u5f84\u7684\u95ee\u9898\u3002\u5728 servlet \u4e2d\u83b7\u53d6\u6587\u4ef6\u8def\u5f84\u65f6\uff0c\u4f7f\u7528 encodeuricomponent(path) \u5bf9\u8def\u5f84\u8fdb\u884c\u7f16\u7801\uff0c\u7136\u540e\u518d\u53d1\u9001\u7ed9\u5ba2\u6237\u7aef\u3002 \u4fee\u6539\u540e\u7684 pdfdownloadservlet \u4ee3\u7801\u5982\u4e0b\uff1a resp.setcontenttype(&#8220;application\/pdf;charset=utf-8&#8221;); resp.setheader(&#8220;content-disposition&#8221;, &#8220;attachment;filename=a.pdf&#8221;); string path = req.getparameter(&#8220;path&#8221;); file w2 = new file(path); logger.info(&#8220;pdf path:&#8221; + w2.getpath()); fileinputstream fs; try { fs = new fileinputstream(w2); [&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-52341","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/52341","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=52341"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/52341\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=52341"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=52341"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=52341"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}