Added splitted

This commit is contained in:
Guillem Hernandez Sola
2026-04-14 11:17:52 +02:00
parent c10c98dfda
commit dd72688e26
2 changed files with 27 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
from pathlib import Path
from pypdf import PdfReader, PdfWriter
def split_pdf_to_single_pages(input_pdf_path: str, output_dir: str = "split_pages") -> None:
input_path = Path(input_pdf_path)
output_path = Path(output_dir)
output_path.mkdir(parents=True, exist_ok=True)
reader = PdfReader(str(input_path))
total_pages = len(reader.pages)
for i, page in enumerate(reader.pages, start=1):
writer = PdfWriter()
writer.add_page(page)
output_file = output_path / f"{input_path.stem}_page_{i}.pdf"
with open(output_file, "wb") as f:
writer.write(f)
print(f"Done! Split {total_pages} pages into {total_pages} single-page PDFs in '{output_path}'.")
if __name__ == "__main__":
# Change this to your file name/path
split_pdf_to_single_pages("/Users/guillemhernandezsola/icloud/agile611/asistencia/Certificado_Asistencia_Jenkins_Eclekte_signed.pdf")