PDF空白頁刪除程序,網上PDF軟件刪除有些需要權限、會員等亂七八糟的,然後通過查找使用python實現了PDF空白頁或者指定頁刪除程序。
可執行程序:https://download.csdn.net/download/zx520113/12344051
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#author:SingWeek
#Time:2020/4/20 16:17
from PyPDF2 import PdfFileReader, PdfFileWriter
# path = "F:\Game\zx.pdf"
while True:
try:
path=input("請輸入待處理文件路徑:")
auto=input("請輸入A自動刪除或者M手動刪除:")
reader = PdfFileReader(open(path, 'rb'))
writer = PdfFileWriter()
pages = reader.getNumPages()
path_output = ".\output.pdf"
if auto.upper()=="A":
for i in range(pages):
page = reader.getPage(i)
if "/XObject" in page["/Resources"].keys() or "/Font" in page["/Resources"].keys():
writer.addPage(page)
else:
dealtmp=input("請輸入刪除頁數例如(4,12):")
deallist=[]
for i in dealtmp.split(","):
deallist.append(int(i))
for i in range(pages):
page = reader.getPage(i)
if i+1 in deallist:
pass
else:
writer.addPage(page)
writer.write(open(path_output, 'wb'))
except:
print("輸入執行錯誤請檢測重新輸入!")
print("當前文件處理完畢!")
out=input("輸入q退出:")
if out=='q':
break