Split PDF to single pages with simple Python script

Publicado em: 09 Agosto 2022
no canal de: 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


Nesta página do site você pode assistir ao vídeo on-line Split PDF to single pages with simple Python script duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário Rafal Kobus 09 Agosto 2022, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 432 vezes e gostou 8 espectadores. Boa visualização!