from io import StringIO from pdfminer.converter import TextConverter from pdfminer.layout import LAParams from pdfminer.pdfdocument import PDFDocument from pdfminer.pdfinterp import PDFResourceManager, PDFPageInterpreter from pdfminer.pdfpage import PDFPage from pdfminer.pdfparser import PDFParser def convert_pdf_to_string(pdf_file): output = StringIO() with open(pdf_file, 'rb') as in_file: parser = PDFParser(in_file) doc = PDFDocument(parser) rsrcmgr = PDFResourceManager() device = TextConverter(rsrcmgr, output, laparams=LAParams()) interpreter = PDFPageInterpreter(rsrcmgr, device) for page in PDFPage.create_pages(doc): interpreter.process_page(page) return(output.getvalue()) def convert_title_to_filename(title): filename = title.lower() filename = filename.replace(' ', '_') return filename def split_to_title_and_pagenum(table_of_contents_entry): title_and_pagenum = table_of_contents_entry.strip() title = None pagenum = None if len(title_and_pagenum) > 0: if title_and_pagenum[-1].isdigit(): i = -2 while title_and_pagenum[i].isdigit(): i -= 1 title = title_and_pagenum[:i].strip() pagenum = int(title_and_pagenum[i:].strip()) return title, pagenum
pdf_name = 'dadjokes.pdf' # .pdf file you want to convert print(convert_pdf_to_string(pdf_name))
DAD JOKES 1. 3. 4. 5. 7. 8. 12. 16. 17. 18. 19. 20. 23. 24. 26. Dad, did you get a haircut? No I got them all cut. 2. What do you call a Mexican who has lost his car? Carlos. Dad, can you put my shoes on? No, I don’t think they’ll fit me. Can I watch the TV? Dad: Yes, but don’t turn it on. I would avoid the sushi if I was you. It’s a little fishy. 6. What do you call a fake noodle? An Impasta. You know, people say they pick their nose, but I feel like I was just born with mine. “Every time I hurt myself, even to this day, my dad says, ‘The good news is..it’ll feel better when it quits hurting.'” 9. What’s brown and sticky? A stick. 10. Want to hear a joke about paper? Nevermind it’s tearable. 11. Did you hear about the restaurant on the moon? Great food, no atmosphere. “I’ll call you later!”- “Please don’t do that. I’ve always asked you to call me Dad!” 13. Q: Why did the cookie cry? A: Because his father was a wafer so long! 14. What did the mountain climber name his son? Cliff. 15. This graveyard looks overcrowded. People must be dying to get in there. “My dad literally told me this one last week: ‘Did you hear about the guy who invented Lifesavers? They say he made a mint.’” “Whenever the cashier at the grocery store asks my dad if he would like the milk in a bag he replies, ‘No, just leave it in the carton!’” I got so angry the other day when I couldn’t find my stress ball. If I had a dime for every book I’ve ever read, I’d say: “Wow, that’s coincidental.” I’m not indecisive. Unless you want me to be. 21. How many apples grow on a tree? All of them. 22. How does a penguin build it’s house? Igloos it together. “Me: ‘Dad, make me a sandwich!’ Dad: ‘Poof, You’re a sandwich!’” “I heard there was a new store called Moderation. They have everything there 25. A steak pun is a rare medium well done. “How can you tell if a ant is a boy or a girl? They’re all girls, otherwise they’d be uncles.” 27. Milk is also the fastest liquid on earth – its pasteurized before you even see it 28. 30. 31. 32. 34. 41. 42. “What’s Forrest Gump’s password? 1forrest1” 29. The only thing worse than having diarrhea is having to spell it. I asked my friend to help me with a math problem. He said: “Don’t worry; this is a piece of cake.” I said: “No, it’s a math problem.” I keep trying to lose weight, but it keeps finding me. I don’t play soccer because I enjoy the sport. I’m just doing it for kicks. 33. Did I tell you the time I fell in love during a backflip? I was heels over head. I used to work in a shoe recycling shop. It was sole destroying. 35. Why do you never see elephants hiding in trees? Because they’re so good at it. 36. Where did the one-legged waitress work? IHOP! 37. What happened when the two antennas got married? Well, the ceremony was kinda boring, but the reception was great! 38. What did one snowman say to the other one? “Do you smell carrots?” 39. How do you make a tissue dance? You put a little boogie in it! 40. Why did the blonde stare at the orange juice container? It said concentrate! If your nose runs and your feet smell, you are built upside down! I went to buy some camouflage trousers the other day, but I couldn’t find any. 43. Q: How do you organize an outer space party? A: You planet. 44. Q: What do you call a belt with a watch on it?A: A waist of time. 45. What kind of shoes does a thief wear? Sneakers 46. A jumper cable walks into a bar. The bartender says, “I’ll serve you, but don’t start anything.” 47. An invisible man marries an invisible woman. The kids were nothing to look at either. 48. I went to a seafood disco last week… and pulled a mussel. 49. Did you hear about the man who stole a calendar? He got 12 months. 50. A man woke up in a hospital after a serious accident. He shouted, Doctor, doctor, I can’t feel my legs!” The doctor replied, “I know you can’t I’ve cut off your arms!” 51. Do you know where you can get chicken broth in bulk? The stock market. 52. What did the ocean say to the shore? Nothing, it just waved. 53. “What’s ET short for? Because he’s only got little legs.” 54. Why do crabs never give to charity? Because they’re shellfish. 55. What do you call an Argentinian with a rubber toe? Roberto “What do you call a man with no nose and no body? Nobody nose.” I cut my finger chopping cheese, but I think that I may have greater problems. 58. What do you call a fish with no eyes? A fshhhh. “What do you call a man with no arms and no legs lying in front of your door? Matt.” 60. My cat was just sick on the carpet, I don’t think it’s feline well. I dreamed about drowning in an ocean made out of orange soda last night. It took me a while to work out it was just a Fanta sea. 62. Without geometry life is pointless. 63. A termite walks into a bar and asks “Is the bar tender here?” I gave all my dead batteries away today… Free of charge. I needed a password eight characters long so I picked Snow White and the Seven Dwarfs. I am terrified of elevators. I’m going to start taking steps to avoid them. 67. What’s the advantage of living in Switzerland? Well, the flag is a big plus. 68. Why did the octopus beat the shark in a fight? Because it was well armed. 69. A red and a blue ship have just collided in the Caribbean. Apparently the survivors are I’ve deleted the phone numbers of all the Germans I know from my mobile phone. Now 56. 57. 59. 61. 64. 65. 66. 70. 71. Last night me and my girlfriend watched three DVDs back to back. Luckily I was the 72. Q: What did daddy spider say to baby spider? A: You spend too much time on the web. 73. How much does a hipster weigh? An instagram. 74. What do you call a group of killer whales playing instruments? An Orca-stra. 75. Why was the big cat disqualified from the race? Because it was a cheetah. 76. Bicycles can’t stand on their own, they’re two tired. 77. Just watched a documentary about beavers… It was the best damn program I’ve ever seen. marooned. it’s Hans free. one facing the TV. 79. 81. 82. 83. 90. 92. 78. Breaking news! Energizer Bunny arrested – charged with battery “How do you make holy water? You boil the hell out of it.” 80. A Sandwich walks into a bar, the bartender says “Sorry, we don’t serve food here” “Doctor, I’ve broken my arm in several places” Doctor “Well don’t go to those places.” I’m on a whiskey diet. I’ve lost three days already. “Why did the Clydesdale give the pony a glass of water? Because he was a little horse!” 84. There’s a new type of broom out, it’s sweeping the nation. 85. Atheism is a non-prophet organisation. 86. Slept like a log last night … woke up in the fireplace. 87. “We were getting fast food when the lady at the window said, ‘Any condiments?’ My dad responded, ‘Compliments? You look very nice today!’” 88. What cheese can never be yours? Nacho cheese. 89. A police officer caught two kids playing with a firework and a car battery. He charged one and let the other one off. I’m reading a book on the history of glue – can’t put it down. 91. Did you hear about the kidnapping at school? It’s fine, he woke up. I went to the zoo the other day, there was only one dog in it. It was a shitzu. 93. What did the daddy tomato say to the baby tomato? A: catch up! 94. Q: What’s 50 Cent’s name in Zimbabwe? A: 400 Million Dollars. 95. Q: What did baby corn say to mama corn? A: Where’s popcorn? 96. What do you call a cow with no legs? Ground beef. 97. What did the Buffalo say to his little boy when he dropped him off at school? Bison. 98. So a duck walks into a pharmacy and says “Give me some chap-stick… and put it on my 99. Why did the scarecrow win an award? Because he was outstanding in his field. 100. Why did the girl smear peanut butter on the road? To go with the traffic jam. 101. Why does a chicken coop only have two doors? Because if it had four doors it would be bill” a chicken sedan. 102. Why don’t seagulls fly over the bay? Because then they’d be bay-gulls! 103. “Two peanuts were walking down the street. One was a salted.” 104. What do you do when a blonde throws a grenade at you? Pull the pin and throw it back. 105. How do you make a hankie dance? Put a little boogie in it. 106. Where does batman go to the bathroom? The batroom. 107. What’s the difference between an African elephant and an Indian elephant? About 5000 miles 108. I’m on a seafood diet… I see food and I eat it. 109. A man walks into a bar and orders helicopter flavor chips. The barman replies “sorry 110. : Commissar! Commissar! The troops are revolting! Commissar: Well, you’re pretty mate we only do plain” repulsive yourself. 111. What do you call a sheep with no legs? A cloud. 112. I knew I shouldn’t have ate that seafood. Because now I’m feeling a little… Eel 113. What did the 0 say to the 8? Nice belt. 114. Why are skeletons so calm? Because nothing gets under their skin. 115. Why don’t skeletons ever go trick or treating? Because they have nobody to go with. 116. Why do scuba divers fall backwards into the water? Because if they fell forwards they’d still be in the boat. 117. Have you ever heard of a music group called Cellophane? They mostly wrap. 118. What kind of magic do cows believe in? MOODOO. 119. Why does Superman gets invited to dinners? Because he is a Supperhero. 120. “Hold on, I have something in my shoe” “I’m pretty sure it’s a foot” 121. Dad I’m hungry … “Hi hungry” I’m dad 122. When phone ringing Dad says ‘If it’s for me don’t answer it. 123. “I asked my dad for his best dad joke and he said, ‘You.’” 124. Where’s the bin? Dad: I haven’t been anywhere!
rr = convert_pdf_to_string(pdf_name) from gtts import gTTS string_of_text = '' for text in rr: string_of_text += text final_file = gTTS(text=string_of_text, lang='en') # store file in variable final_file.save("pdf2Speech.mp3") # save file to computer