CMSiMDE 網際內容管理系統

  • Home
    • Site Map
    • reveal
    • blog
  • 40823111
  • 上課內容
    • W10-W11
      • python
    • W12
      • 把1個PDF可以解取幾頁到幾頁
      • 把1個PDF 可以解取多個分段
      • 把PDF結合再一起
    • W13-W15
    • W16-W17
  • 加入ssh
  • 網頁Cmsimde 建立方法
  • 用@gm帳號建blog
  • 如何在虛擬主機 git clone
  • Pelican建立Blog
W12 << Previous Next >> 把1個PDF 可以解取多個分段

把1個PDF可以解取幾頁到幾頁

# pypdf2_ex1.py
import os
from PyPDF2 import PdfFileWriter, PdfFileReader
 
pdfReader = PdfFileReader(open("2002_Book_Real-WorldASPNETBuildingAConte.pdf", "rb"))
information = [("WhatIsCMS",18,45)]
 
for page in range(len(information)):
    pdf_writer = PdfFileWriter()
    start = information[page][1]
    end = information[page][2]
    while start<=end:
        pdf_writer.addPage(pdfReader.getPage(start-1))
        start+=1
    if not os.path.exists("./"):
        os.makedirs(savepath)
    output_filename = '{}_{}_page_{}.pdf'.format(information[page][0],information[page][1], information[page][2])
    with open(output_filename,'wb') as out:
        pdf_writer.write(out)

W12 << Previous Next >> 把1個PDF 可以解取多個分段

Copyright © All rights reserved | This template is made with by Colorlib