Added splitted
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -22,6 +22,7 @@ media/xhs_videos
|
|||||||
*.xls
|
*.xls
|
||||||
.env
|
.env
|
||||||
*.env
|
*.env
|
||||||
|
*.pdf
|
||||||
|
|
||||||
# Generated files
|
# Generated files
|
||||||
.idea/**/contentModel.xml
|
.idea/**/contentModel.xml
|
||||||
|
|||||||
26
file-management/split-pdfs.py
Normal file
26
file-management/split-pdfs.py
Normal 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")
|
||||||
Reference in New Issue
Block a user