MCPcopy Index your code
hub / github.com/geekcomputers/Python / pdf_read

Function pdf_read

VoiceAssistant/Project_Basic_struct/textRead.py:38–245  ·  view source on GitHub ↗

[Print and speak out the pdf on specified path]

()

Source from the content-addressed store, hash-verified

36
37
38def 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)

Callers 1

mainFunction · 0.85

Calls 8

speakFunction · 0.90
hearFunction · 0.90
doubleslashFunction · 0.85
book_detailsFunction · 0.85
print_indexFunction · 0.85
print_n_speak_indexFunction · 0.85
search_in_tocFunction · 0.85
closeMethod · 0.45

Tested by

no test coverage detected