{"id":1346,"date":"2010-10-11T09:06:00","date_gmt":"2010-10-11T01:06:00","guid":{"rendered":""},"modified":"2013-11-20T21:13:20","modified_gmt":"2013-11-20T13:13:20","slug":"html%e8%bd%ac%e6%8d%a2%e6%88%90pdf%e5%b7%a5%e5%85%b7%ef%bc%9awkhtmltopdf","status":"publish","type":"post","link":"https:\/\/kyle.ai\/blog\/1346.html","title":{"rendered":"HTML\u8f6c\u6362\u6210PDF\u5de5\u5177\uff1awkhtmltopdf"},"content":{"rendered":"<p>\u6709\u65f6\u5019\u6211\u4eec\u9700\u8981\u628aHTML\u9875\u9762\u5185\u5b58\u8f6c\u6362\u6210PDF\uff0c\u5f53\u7136\u53ef\u4ee5\u622a\u56fe\u505a\u6210Excel\u7136\u540e\u8f6c\u6362\u6210PDF\u3002\u4e0b\u9762\u4ecb\u7ecd\u4e00\u4e0bHTML\u8f6c\u6362\u6210PDF\u7684\u5de5\u5177wkhtmltopdf\uff08http:\/\/code.google.com\/p\/wkhtmltopdf\/ \uff09\u3002\u8fd9\u4e2a\u5de5\u5177\u53ef\u4ee5\u5728Linux\u548cWindows\u7b49\u7cfb\u7edf\u4e0b\u8fd0\u884c\u3002<\/p>\n<p>\u4e0b\u9762\u4ee5Windows\u4e3a\u4f8b\u5b50\u3002\u5148\u4e0b\u8f7d\u5de5\u5177wkhtmltopdf-\u7248\u672c\u53f7-.exe\u3002\u4e0b\u8f7d\u628a\u6587\u4ef6\u653e\u5230\u81ea\u5df1\u4e2a\u4e00\u4e2a\u6587\u4ef6\u5939\u4e0b\u9762\uff0c\u6bd4\u5982D:\\tool\\htmltopdf\u3002\u7136\u540e\u542f\u52a8\u547d\u4ee4\u884c\uff0c\u5728\u547d\u4ee4\u884c\u91cc\u9762\u8f93\u5165\u547d\u4ee4\u5c31\u53ef\u4ee5\u6267\u884c\u8f6c\u6362\u4e86\u3002<\/p>\n<p>\u8fd9\u8fb9\u4ee5CSDN\u4e3b\u9875\u4e3a\u4f8b\u5b50\uff1awkhtmltopdf-0.8.3.exe www.csdn.com myhomepage.pdf<\/p>\n<p>\u6ce8\u610f\u82e5\u9047\u5230\u7f16\u7801\u4e71\u7801\u7684\u95ee\u9898\uff0c\u9700\u8981\u4fee\u6539\u9875\u9762\u7684\u7f16\u7801\uff0c\u7528Dreamweaver\u4fee\u6539\u7f51\u9875\u7684\u7f16\u7801\uff0c\u7f16\u8f91\u3001\u9875\u9762\u5c5e\u6027\u91cc\u9762\u3002<\/p>\n<p>\u8fd9\u91ccwkhtmltopdf-0.8.3.exe\u4e0b\u8f7d\u7684\u7a0b\u5e8f\u540d\uff0cwww.csdn.com\u662f\u8981\u8f93\u51fa\u4e3aPDF\u7684HTML\u7684URL\uff0cmyhomepage.pdf\u662f\u8f93\u51fa\u7684PDF\u6587\u4ef6\u540d\u3002<\/p>\n<p><img decoding=\"async\" src=\".\/wp-content\/uploads\/hibaidu\/0b24e5c5b60403e18226acac.jpg\" alt=\"\" border=\"0\" \/><\/p>\n<p>Linux\u4e2d\u7684\u547d\u4ee4\u662f\uff1awkhtmltopdf www . myhomepage . com myhomepage . pdf<\/p>\n<p>\u8fd8\u53ef\u4ee5\u901a\u8fc7 wkhtmltopdf &#8212; help \u547d\u4ee4\u6765\u67e5\u770b\u5176\u5b83\u53c2\u6570\u548c\u5e2e\u52a9\u3002<\/p>\n<p>\u751f\u6210\u7684pdf\u6548\u679c\u5982\u4e0b\uff1a<\/p>\n<p><img decoding=\"async\" src=\".\/wp-content\/uploads\/hibaidu\/01059551c68f952a853524b0.jpg\" alt=\"\" border=\"0\" \/><\/p>\n<p>\u4e0b\u9762\u7ed9\u51fa\u5728C#\u4e0b\u7684\u8c03\u7528\u65b9\u6cd5\uff1a<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nusing System.Diagnostics;\r\n    \/\/\/ &lt;summary&gt;\r\n    \/\/\/ HTML\u751f\u6210PDF\r\n    \/\/\/ &lt;\/summary&gt;\r\n    \/\/\/ &lt;param name=&quot;url&quot;&gt;\u5730\u5740&lt;\/param&gt;\r\n    \/\/\/ &lt;param name=&quot;path&quot;&gt;PDF\u5b58\u653e\u8def\u5f84&lt;\/param&gt;\r\n    public static bool HtmlToPdf(string url, string path)\r\n    {\r\n        try\r\n        {\r\n            if (string.IsNullOrEmpty(url) || string.IsNullOrEmpty(path))\r\n                return false;\r\n            Process p = new Process();\r\n            string str = System.Web.HttpContext.Current.Server.MapPath(&quot;wkhtmltopdf.exe&quot;);\r\n            if (!System.IO.File.Exists(str))\r\n                return false;\r\n            p.StartInfo.FileName = str;\r\n            p.StartInfo.Arguments = &quot; \\&quot;&quot; + url + &quot;\\&quot; &quot; + path;\r\n            p.StartInfo.UseShellExecute = false;\r\n            p.StartInfo.RedirectStandardInput = true;\r\n            p.StartInfo.RedirectStandardOutput = true;\r\n            p.StartInfo.RedirectStandardError = true;\r\n            p.StartInfo.CreateNoWindow = true;\r\n            p.Start();\r\n            System.Threading.Thread.Sleep(500);\r\n\r\n            return true;\r\n        }\r\n        catch (Exception ex)\r\n        {\r\n            HttpContext.Current.Response.Write(ex);\r\n        }\r\n        return false;\r\n    }\r\n<\/pre>\n<p>\u8c03\u7528\u65b9\u6cd5\uff1aHtmlToPdf(&#8220;\u7f51\u9875URL&#8221;, Server.MapPath(&#8220;PDF\u5b58\u653e\u8def\u5f84&#8221;));<\/p>\n<p>\u9700\u8981\u6ce8\u610f\u7684\u662f\uff1a\u4f7f\u7528wkhtmltopdf\u65f6\uff0cPDF\u4fdd\u5b58\u7684\u6587\u4ef6\u5939\u4e0d\u80fd\u6709\u975eAnsi\u5b57\u7b26\uff0c\u5982\u4e2d\u6587\u3001\u65e5\u6587\u7b49\uff0c\u4e14\u8f6c\u6362gb2312\u3001\u97e9\u6587charset\u3001\u65e5\u6587charset\u7b49\u975eutf-8\\ansi\u7b49\u7f51\u9875\u65f6\uff0c\u4f1a\u51fa\u73b0\u4e71\u7801\u3002<\/p>\n<p>\u672c\u5730\u6587\u4ef6\u51fa\u73b0\u4e71\u7801\uff0c\u53ef\u7528DW\u4fee\u6539HTML\u7684\u7f16\u7801\u4e3aUTF8\uff0c\u518d\u7528\u8bb0\u4e8b\u672c\u6253\u5f00\uff0c\u53e6\u5b58\u4e3a\uff0c\u9009\u62e9\u7f16\u7801\u4e3aUTF8\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6709\u65f6\u5019\u6211\u4eec\u9700\u8981\u628aHTML\u9875\u9762\u5185\u5b58\u8f6c\u6362\u6210PDF\uff0c\u5f53\u7136\u53ef\u4ee5\u622a\u56fe\u505a\u6210Excel\u7136\u540e\u8f6c\u6362\u6210PDF\u3002\u4e0b\u9762\u4ecb\u7ecd\u4e00\u4e0bHTML [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-1346","post","type-post","status-publish","format-standard","hentry","category-tool_tutorial"],"_links":{"self":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/1346","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/comments?post=1346"}],"version-history":[{"count":2,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/1346\/revisions"}],"predecessor-version":[{"id":4980,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/1346\/revisions\/4980"}],"wp:attachment":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/media?parent=1346"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/categories?post=1346"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/tags?post=1346"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}