[Print and speak out the pdf on specified path]
()
| 36 | |
| 37 | |
| 38 | def pdf_read(): |
| 39 | """[Print and speak out the pdf on specified path]""" |
| 40 | try: |
| 41 | speak("Enter the document's location - ") |
| 42 | location = input("Enter the document's location - ") |
| 43 | |
| 44 | path = doubleslash(location) |
| 45 | pdf = fitz.open(path) |
| 46 | details = pdf.metadata # Stores the meta-data which generally includes Author name and Title of book/document. |
| 47 | total_pages = pdf.pageCount # Stores the total number of pages |
| 48 | |
| 49 | except Exception as exp: |
| 50 | print(f"ERROR - {exp}") |
| 51 | print( |
| 52 | Fore.YELLOW |
| 53 | + "I could'nt locate the file!\nIf you didn't specify the extension of the file, please specify it." |
| 54 | ) |
| 55 | return "None" |
| 56 | try: |
| 57 | """ 1. Author |
| 58 | 2. Creator |
| 59 | 3. Producer |
| 60 | 4. Title """ |
| 61 | |
| 62 | author = details["author"] |
| 63 | # print("Author : ",author) |
| 64 | |
| 65 | title = details["title"] |
| 66 | # print("Title : ",title) |
| 67 | |
| 68 | # print(details) |
| 69 | # print("Total Pages : ",total_pages) |
| 70 | book_details(author, title, total_pages) |
| 71 | speak(f" Title {title}") |
| 72 | speak(f" Author {author}") |
| 73 | speak(f" Total Pages {total_pages}") |
| 74 | |
| 75 | # TODO : Deal with the Index |
| 76 | toc = pdf.get_toc() |
| 77 | print( |
| 78 | "Say 1 or \"ONLY PRINT INDEX\" - if you want me to print the book's index.\nSay 2 if you want me to print and make me speak out the book's index.\nSay any key if you don't want to print the index.'" |
| 79 | ) |
| 80 | speak( |
| 81 | "Say 1 or only print index if you want me to print the book's index.\nSay 2 if you want me to print and make me speak out the book's index.\nSay any key if you don't want to print the index.'" |
| 82 | ) |
| 83 | q = hear().lower() |
| 84 | |
| 85 | if ( |
| 86 | "only print" in q |
| 87 | or "1" in q |
| 88 | or "one" in q |
| 89 | or "vone" in q |
| 90 | or "only" in q |
| 91 | or "index only" in q |
| 92 | or "only" in q |
| 93 | or "print only" in q |
| 94 | ): |
| 95 | print_index(toc) |
no test coverage detected