wcm2020 12

  • Home
    • Site Map
    • reveal
    • blog
  • HOME
  • 每周上課內容
  • 上課內容整理
    • W10
      • Python程式
      • CSV
    • W12
      • 建立虛擬主機
    • W14
      • MBR與GPT
      • BIOS與UEFI
    • W15
      • 利用Pypdf2來切割PDF檔
    • W16
      • 何謂wsgi
    • W17
      • PDF網際分割與合併程式
      • 何謂 API
      • 何謂 URI
      • 何謂 URL 、 URN
  • 錯誤修正
    • 命令列無法使用pip下載程式
  • 操作步驟教學
    • 如何建網頁
    • 如何使用SSH維護倉儲
    • 如何安裝虛擬主機
    • 如何使用leo編輯Palican
    • 如何在虛擬主機上clone倉儲
W15 << Previous Next >> W16

利用Pypdf2來切割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)

W15 << Previous Next >> W16

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