KarthikaRajagopal commited on
Commit
6fc6a02
Β·
verified Β·
1 Parent(s): e7f5e94

Delete pdf_manager.py

Browse files
Files changed (1) hide show
  1. pdf_manager.py +0 -42
pdf_manager.py DELETED
@@ -1,42 +0,0 @@
1
- from pdf2image import convert_from_path
2
- import os
3
- import shutil
4
-
5
- class PdfManager:
6
- def __init__(self):
7
- pass
8
-
9
- def clear_and_recreate_dir(self, output_folder):
10
- print(f"Clearing output folder {output_folder}")
11
-
12
- if os.path.exists(output_folder):
13
- shutil.rmtree(output_folder)
14
-
15
- os.makedirs(output_folder)
16
-
17
- def save_images(self, id, pdf_path, max_pages, pages: list[int] = None) -> list[str]:
18
- output_folder = f"pages/{id}/"
19
- images = convert_from_path(pdf_path)
20
-
21
- print(f"Saving images from {pdf_path} to {output_folder}. Max pages: {max_pages}")
22
-
23
- self.clear_and_recreate_dir(output_folder)
24
-
25
- num_page_processed = 0
26
-
27
- for i, image in enumerate(images):
28
- if max_pages and num_page_processed >= max_pages:
29
- break
30
-
31
- if pages and i not in pages:
32
- continue
33
-
34
- full_save_path = f"{output_folder}/page_{i + 1}.png"
35
-
36
- #print(f"Saving image to {full_save_path}")
37
-
38
- image.save(full_save_path, "PNG")
39
-
40
- num_page_processed += 1
41
-
42
- return [f"{output_folder}/page_{i + 1}.png" for i in range(num_page_processed)]