Successful implimentation of tqdm progress bar in pdfplumber. #541
-
Hi, has anyone successfully implimented a tqdm progress bar with the progress out extract from a .pdf, For instance i would like my progress bar to add 1% when it has done 1/100 pages. I would find this super useful as i regularly have documents with thousands of pages and struggle to see where at in the process my code is. Until it reaches the next step then i can I currently use the following method:
However i was unsure how to impliment tqdm without a for loop which is in the tqdm documentation. So i tried the following code however it doesnt seem to do anything progress bar wise.
Any help of example code of it work that i can adjust and ammend accordingly would be really helpful. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi @LeeSugden Appreciate your interest in the library. I tried with a different approach and it works fine. Here it is from tqdm import tqdm
import pdfplumber
def progress_bar_test():
pdf = pdfplumber.open("file.pdf")
pbar = tqdm(total=len(pdf.pages))
for page in pdf.pages:
text = page.extract_text()
pbar.update(1)
pbar.close()
if __name__ == "__main__":
progress_bar_test() The final output was $ python main.py
100%|█████████████████████████████████████████████| 8/8 [00:02<00:00, 3.49it/s] It goes from 1 to the number of pages but you can easily configure it if you want to go from 10 to 100. |
Beta Was this translation helpful? Give feedback.
Hi @LeeSugden Appreciate your interest in the library. I tried with a different approach and it works fine. Here it is
The final output was
It goes from 1 to the number of pages but you can easily configure it if you want to go from 10 to 100.