{"id":130,"date":"2019-12-19T00:08:53","date_gmt":"2019-12-18T16:08:53","guid":{"rendered":"http:\/\/blog.cyasylum.top\/?p=130"},"modified":"2019-12-19T10:33:08","modified_gmt":"2019-12-19T02:33:08","slug":"ppt%e6%89%b9%e5%a4%84%e7%90%86%e8%bd%acpptx","status":"publish","type":"post","link":"http:\/\/blog.cyasylum.top\/index.php\/2019\/12\/19\/ppt%e6%89%b9%e5%a4%84%e7%90%86%e8%bd%acpptx\/","title":{"rendered":"ppt\u6279\u5904\u7406\u8f6cpptx\/pdf"},"content":{"rendered":"<p>\u4e3a\u4e86\u8ba9iPad\u80fd\u591f\u8f83\u65b9\u4fbf\u5730\u5f00\u542fPPT\u6587\u4ef6\uff0c\u88ab\u8feb\u5199\u4e00\u4e2a\u5e2e\u52a9ppt\u8fdb\u884c\u9ad8\u901f\u548f\u5531\u7684\u6279\u5904\u7406\u7a0b\u5e8f<\/p>\n<pre><code class=\"language-python\">import comtypes.client\nimport os\n\n# \u521b\u5efappt\u5bf9\u8c61\ndef init_powerpoint():\n    powerpoint = comtypes.client.CreateObject(&#039;Powerpoint.Application&#039;)\n    powerpoint.Visible = 1\n    return powerpoint\n\n# \u6253\u5f00ppt\uff0c\u66f4\u6362\u540e\u7f00\u4e3apptx\ndef ppt_to_pptx(powerpoint, inputFileName):\n    if(inputFileName[-3:] == &#039;ppt&#039;):\n        outputFileName = inputFileName[:-4] + &#039;.pptx&#039;\n        app = powerpoint.Presentations.Open(inputFileName)\n        app.SaveAs(outputFileName)\n        app.Close()\n\n# \u6253\u5f00\u6587\u4ef6\uff0c\u8f93\u51fapdf\uff0c\u9ed8\u8ba4\u683c\u5f0f\u531632\ndef ppt_to_pdf(powerpoint, inputFileName, formatType=32):\n    if(inputFileName[-3:] == &#039;ppt&#039;):\n        outputFileName = inputFileName[:-4] + &quot;.pdf&quot;\n        app = powerpoint.Presentations.Open(inputFileName)\n        app.SaveAs(outputFileName, formatType)\n        app.Close()\n    if(inputFileName[-4:] == &#039;pptx&#039;):\n        outputFileName = inputFileName[:-5] + &quot;.pdf&quot;\n        app = powerpoint.Presentations.Open(inputFileName)\n        app.SaveAs(outputFileName, formatType)\n        app.Close()\n\n# \u5bf9\u6240\u6709ppt\u7c7b\u578b\u6587\u4ef6\u5e94\u7528\ndef switch_the_fucking_ppt(powerpoint, folder, mod):\n    files = os.listdir(folder)\n    ppts = [f for f in files if f.endswith((&quot;.ppt&quot;, &quot;.pptx&quot;))]\n    for ppt in ppts:\n        path = os.path.join(folder, ppt)\n        if mod == 1:\n            ppt_to_pptx(powerpoint, path)\n        elif mod == 2:\n            ppt_to_pdf(powerpoint, path)\n        else:\n            return\n\nif __name__ == &quot;__main__&quot;:\n    folder = input(&#039;\u8bf7\u8f93\u5165\u6587\u4ef6\u5939\u5730\u5740\uff0c\u5982\\&#039;C:\\\\Users\\\\Syan\\\\Desktop\\\\\u5927\u5b66\u7269\u7406\\&#039;:\\n&#039;)\n    mod = int(input(&#039;\u8bf7\u8f93\u5165\u8981\u6267\u884c\u7684\u64cd\u4f5c\uff1a\\n1\u3001ppt2pptx\\n2\u3001ppt\/pptx2pdf\\n&#039;))\n    powerpoint = init_powerpoint()\n    switch_the_fucking_ppt(powerpoint, folder, mod)\n    powerpoint.Quit()\n<\/code><\/pre>\n<p>\u53c2\u8003\u4e86<a href=\"https:\/\/www.cnblogs.com\/Ghost-bird\/p\/10530256.html\" title=\"Python\u6279\u91cf\u5c06ppt\u8f6c\u6362\u4e3apdf\" target=\"_blank\"  rel=\"nofollow\" >\u300aPython\u6279\u91cf\u5c06ppt\u8f6c\u6362\u4e3apdf\u300b<\/a>\uff0c\u611f\u8c22\u4e00\u4e0b\u4f5c\u8005<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e3a\u4e86\u8ba9iPad\u80fd\u591f\u8f83\u65b9\u4fbf\u5730\u5f00\u542fPPT\u6587\u4ef6\uff0c\u88ab\u8feb\u5199\u4e00\u4e2a\u5e2e\u52a9ppt\u8fdb\u884c\u9ad8\u901f\u548f\u5531\u7684\u6279\u5904\u7406\u7a0b\u5e8f import comtypes.clien &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"templates\/template-full-width.php","format":"standard","meta":{"emotion":"","emotion_color":"","title_style":"","license":"","footnotes":""},"categories":[15],"tags":[16],"class_list":["post-130","post","type-post","status-publish","format-standard","hentry","category-15","tag-python"],"_links":{"self":[{"href":"http:\/\/blog.cyasylum.top\/index.php\/wp-json\/wp\/v2\/posts\/130","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/blog.cyasylum.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.cyasylum.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.cyasylum.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.cyasylum.top\/index.php\/wp-json\/wp\/v2\/comments?post=130"}],"version-history":[{"count":3,"href":"http:\/\/blog.cyasylum.top\/index.php\/wp-json\/wp\/v2\/posts\/130\/revisions"}],"predecessor-version":[{"id":136,"href":"http:\/\/blog.cyasylum.top\/index.php\/wp-json\/wp\/v2\/posts\/130\/revisions\/136"}],"wp:attachment":[{"href":"http:\/\/blog.cyasylum.top\/index.php\/wp-json\/wp\/v2\/media?parent=130"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.cyasylum.top\/index.php\/wp-json\/wp\/v2\/categories?post=130"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.cyasylum.top\/index.php\/wp-json\/wp\/v2\/tags?post=130"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}