Split PDF to single pages with simple Python script

Publié le: 09 août 2022
sur la chaîne: Rafal Kobus
432
8

Rafal Kobus

  / rafa%c5%82-kobus-b6051314b  

from PyPDF2 import PdfFileReader, PdfFileWriter
import os
import sys
import glob
abspath = os.path.abspath(__file__)
dname = os.path.dirname(abspath)
os.chdir(dname)

if getattr(sys, 'frozen', False):
_location_ = os.path.dirname(os.path.realpath(sys.executable))
elif __file__:
_location_ = os.path.realpath(
os.path.join(os.getcwd(), os.path.dirname(__file__)))

for file in glob.glob(__location__ + "/*.pdf"):
if file.endswith('.pdf'):
pdf_file = open(os.path.join(__location__, file), 'rb')
pdf_reader = PdfFileReader(pdf_file)

pageNumbers = pdf_reader.getNumPages()

for i in range (pageNumbers):
pdf_writer = PdfFileWriter()
pdf_writer.addPage(pdf_reader.getPage(i))
split_motive = open('Page ' + str(i+1) + '.pdf', 'wb')
pdf_writer.write(split_motive)
split_motive.close()

pdf_file.close()

#PyPDF2 #PDF #Python


Sur cette page du site, vous pouvez voir la vidéo en ligne Split PDF to single pages with simple Python script durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur Rafal Kobus 09 août 2022, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 432 fois et il a aimé 8 téléspectateurs. Bon visionnage!