{"id":650,"date":"2020-06-04T15:51:11","date_gmt":"2020-06-04T06:51:11","guid":{"rendered":"https:\/\/blog.wewidi.com\/?p=650"},"modified":"2020-06-04T16:14:37","modified_gmt":"2020-06-04T07:14:37","slug":"%e3%80%90python%e3%80%91pdf-file%e3%81%ae%e5%85%a8%e3%81%a6%e3%81%ae%e3%83%9a%e3%83%bc%e3%82%b8%e3%82%92%e9%80%86%e9%a0%86%e3%81%ab%e3%81%99%e3%82%8b","status":"publish","type":"post","link":"https:\/\/blog.wewidi.com\/?p=650","title":{"rendered":"\u3010Python\u3011PDF File\u306e\u5168\u3066\u306e\u30da\u30fc\u30b8\u3092\u9006\u9806\u306b\u3059\u308b"},"content":{"rendered":"\n<p>\u66f8\u7c4d\u306a\u3069\u3092\u4fdd\u5b58\u3057\u3066\u304a\u304f\u305f\u3081\u306b\u66f8\u7c4d\u3092\u81ea\u708a\u3059\u308b\u3053\u3068\u304c\u3042\u308b\u3002<\/p>\n\n\n\n<p>\u30b9\u30ad\u30e3\u30f3\u306b\u554f\u984c\u306a\u3051\u308c\u3070\u3001\u4e21\u9762\u53d6\u308a\u8fbc\u307f\u3067\u5168\u3066\u306e\u30da\u30fc\u30b8\u304c\u53d6\u308a\u8fbc\u3081\u308b\u306e\u3060\u304c\u3001\u672c\u306e\u30b5\u30a4\u30ba\u3084\u7d19\u8cea\u304c\u7279\u6b8a\u306a\u672c\u306e\u5834\u5408\u3001\u4e0a\u624b\u3044\u3053\u3068\u30b9\u30ad\u30e3\u30f3\u3067\u304d\u305a\u3001\u7247\u9762\u53d6\u308a\u8fbc\u307f\u3067\u8868\u9762\uff08\u5947\u6570\u30da\u30fc\u30b8\uff09\u3001\u88cf\u9762\uff08\u5076\u6570\u30da\u30fc\u30b8\uff09\u3092\u305d\u308c\u305e\u308c\u53d6\u308a\u8fbc\u307e\u306a\u304f\u3066\u306f\u306a\u3089\u306a\u3044\u5834\u5408\u304c\u3042\u308b\u3002<\/p>\n\n\n\n<p>\u5947\u6570\u30da\u30fc\u30b8\u3067\u3042\u308c\u3070\u3001\u305d\u306e\u307e\u307e\u30da\u30fc\u30b8\u306e\u82e5\u3044\u9806\u306b\u53d6\u308a\u8fbc\u3080\u3053\u3068\u304c\u51fa\u6765\u308b\u304c\u3001\u5076\u6570\u30da\u30fc\u30b8\u306e\u5834\u5408\u3001\u6700\u5f8c\u306e\u30da\u30fc\u30b8\u304b\u3089\u30b9\u30ad\u30e3\u30f3\u3055\u308c\u308b\u306e\u3067\u30da\u30fc\u30b8\u9806\u304c\u9006\u3067\u53d6\u308a\u8fbc\u307e\u308c\u308b\u3053\u3068\u306b\u306a\u308b\u3002<\/p>\n\n\n\n<p>\u53d6\u308a\u8fbc\u3080\u524d\u306b\u5168\u3066\u306e\u30da\u30fc\u30b8\u3092\u624b\u3067\u5165\u308c\u63db\u3048\u308c\u3070\u3001\u5947\u6570\u30da\u30fc\u30b8\u3068\u540c\u69d8\u306b\u30da\u30fc\u30b8\u306e\u82e5\u3044\u9806\u3067\u53d6\u308a\u8fbc\u3080\u3053\u3068\u304c\u51fa\u6765\u308b\u304c\u3001\u6570\u5341\u3001\u6570\u767e\u30da\u30fc\u30b8\u3082\u3042\u308b\u3082\u306e\u3092\u3001\u624b\u3067\u5165\u308c\u63db\u3048\u308b\u306e\u306f\u3001\u73fe\u5b9f\u7684\u3067\u306f\u306a\u3044\u3002<\/p>\n\n\n\n<p>Acrobat DC\u306b\u306f\u3001\u30da\u30fc\u30b8\u3092\u9006\u8ee2\u3059\u308b\u6a5f\u80fd\uff08\u30a2\u30af\u30b7\u30e7\u30f3\u30b9\u30af\u30ea\u30d7\u30c8\uff09\u304c\u3042\u308b\u306e\u3067\u3001Acrobat DC\u3092\u6240\u6709\u3057\u3066\u3044\u308b\u4eba\u306f\u3001\u305d\u308c\u3092\u5229\u7528\u3059\u308b\u306e\u304c\u65e9\u3044\u3002<\/p>\n\n\n\n<p>\u3055\u3066\u3001Acrobat DC\u3092\u6301\u3063\u3066\u3044\u306a\u3044\u5834\u5408\u306f\u3069\u3046\u3059\u308b\u304b\u3002<br>\u540c\u69d8\u306a\u3053\u3068\u304c\u51fa\u6765\u308bPDF\u7de8\u96c6\u30bd\u30d5\u30c8\u306f\u3001\u6570\u591a\u304f\u8ca9\u58f2\u3055\u308c\u3066\u3044\u308b\u306e\u3067\u3001\u305d\u308c\u3092\u8cfc\u5165\u3057\u3066\u3082\u826f\u3044\u3068\u601d\u3046\u304c\u3001\u306a\u308b\u3079\u304f\u304a\u91d1\u3092\u639b\u3051\u305a\u306b\u3001\u3084\u308a\u305f\u3044\u3053\u3068\u3092\u5b9f\u73fe\u3057\u305f\u3044\u3002<\/p>\n\n\n\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u3068\u308a\u3042\u3048\u305a\u306a\u3093\u3067\u3082\u51fa\u6765\u3066\u3057\u307e\u3046Python\u3067\u3084\u3063\u3066\u307f\u305f\u3002<\/p>\n\n\n\n<p>\u6d41\u308c\u3068\u3057\u3066\u306f\u3001PDF\u304b\u3089\u7dcf\u30da\u30fc\u30b8\u6570\u3092\u53d6\u5f97\u3057\u3066\u3001\u6700\u5f8c\u306e\u30da\u30fc\u30b8\u304b\u3089\u53d6\u5f97\u3057\u3066\u3001\u65b0\u3057\u3044\u30d5\u30a1\u30a4\u30eb\u306b\u66f8\u304d\u8fbc\u3093\u3067\u3044\u304f\u3002\u3053\u308c\u3060\u3051\u3002Python\u3066\u672c\u5f53\u306b\u4fbf\u5229\u3002<\/p>\n\n\n\n<p>\u30d7\u30ed\u30b0\u30e9\u30e0\u304c\u3042\u308b\u7a0b\u5ea6\u5224\u308b\u4eba\u306a\u3089\u7279\u306b\u89e3\u8aac\u3059\u308b\u5fc5\u8981\u3082\u7121\u3044\u307b\u3069\u5358\u7d14\u306a\u30ed\u30b8\u30c3\u30af\u3067\u3059\u306d\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p><strong>ReverseToBook.py<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">from PyPDF2 import PdfFileReader, PdfFileWriter\n\ndef merge_pdfs(path, output):\n  pdf_writer = PdfFileWriter()\n<code>  pdf_reader = PdfFileReader(path)<\/code>\n<code>  maxPageNum = pdf_reader.getNumPages()<\/code>\n  # \u6700\u5f8c\u306e\u30da\u30fc\u30b8\u304b\u3089\u8aad\u307f\u8fbc\u3093\u3067\u3001\u65b0\u3057\u3044PDF\u306b\u8ffd\u52a0\u3057\u3066\u3044\u304f\n<code>  for page in range(maxPageNum, 0, -1):<\/code>\n  <code>  pdf_writer.addPage(pdf_reader.getPage(page-1))<\/code>\n<code>  # \u65b0\u3057\u3044PDF\u306b\u51fa\u529b<\/code>\n<code>  with open(output, 'wb') as out: pdf_writer.write(out)<\/code>\n\nif __name__ == '__main__':\n  # \u3053\u3053\u306b\u30d5\u30a1\u30a4\u30eb\u540d\u3092\u8a2d\u5b9a\n  path = '\u9006\u30da\u30fc\u30b8\u306b\u306a\u3063\u3066\u3044\u308b.pdf'\n  # output\u306b\u51fa\u529b\u30d5\u30a1\u30a4\u30eb\u540d\u3092\u8a2d\u5b9a\n  merge_pdfs(path, output='reverced.pdf')<\/pre>\n\n\n\n<p>\u3010\u5fc5\u8981\u306a\u3082\u306e\u3011 <br>\u3000\u3000\u30fbPyPdf2 <\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u66f8\u7c4d\u306a\u3069\u3092\u4fdd\u5b58\u3057\u3066\u304a\u304f\u305f\u3081\u306b\u66f8&#8230;<\/p>\n","protected":false},"author":1,"featured_media":179,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[6,20,21,4],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/blog.wewidi.com\/index.php?rest_route=\/wp\/v2\/posts\/650"}],"collection":[{"href":"https:\/\/blog.wewidi.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.wewidi.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.wewidi.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.wewidi.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=650"}],"version-history":[{"count":6,"href":"https:\/\/blog.wewidi.com\/index.php?rest_route=\/wp\/v2\/posts\/650\/revisions"}],"predecessor-version":[{"id":658,"href":"https:\/\/blog.wewidi.com\/index.php?rest_route=\/wp\/v2\/posts\/650\/revisions\/658"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.wewidi.com\/index.php?rest_route=\/wp\/v2\/media\/179"}],"wp:attachment":[{"href":"https:\/\/blog.wewidi.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=650"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.wewidi.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=650"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.wewidi.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=650"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}