You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, new and struggling to find out what is wrong with my directory syntax per the bolded lines below? I'm getting a syntax error on a windows system. Thank you!
import PyPDF2
def extract_text_from_pdf('C:/Users/jwoods/Desktop/py/E1.pdf'):
with open('C:/Users/jwoods/Desktop/py/E1.pdf', 'rb') as pdf_file:
pdf_reader = PyPDF2.PdfReader(pdf_file)
num_pages = len(pdf_reader.pages)
extracted_text = ""
for page_number in range(num_pages):
page = pdf_reader.pages[page_number]
extracted_text += page.extract_text()
return extracted_text
def save_text_as_txt(text, txt_path):
with open(txt_path, 'w', encoding='utf-8') as txt_file:
txt_file.write(text)
Provide the name of the PDF file in the working directory
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello, new and struggling to find out what is wrong with my directory syntax per the bolded lines below? I'm getting a syntax error on a windows system. Thank you!
import PyPDF2
def extract_text_from_pdf('C:/Users/jwoods/Desktop/py/E1.pdf'):
with open('C:/Users/jwoods/Desktop/py/E1.pdf', 'rb') as pdf_file:
pdf_reader = PyPDF2.PdfReader(pdf_file)
num_pages = len(pdf_reader.pages)
extracted_text = ""
def save_text_as_txt(text, txt_path):
with open(txt_path, 'w', encoding='utf-8') as txt_file:
txt_file.write(text)
Provide the name of the PDF file in the working directory
pdf_filename = 'input.pdf'
Extract text from the PDF
extracted_text = extract_text_from_pdf(pdf_filename)
Save the extracted text as a TXT file in the working directory
txt_filename = 'output.txt'
save_text_as_txt(extracted_text, txt_filename)
print('Text extracted and saved as:', txt_filename)
Beta Was this translation helpful? Give feedback.
All reactions