Fantastic. Exactly what I am looking for. Thanks buddy! One quick question. I found you are using 3 PDF files for this demo which are named file1, file2, file3. Should the PDF names should be in some sequential order for iterating each files through loop or can the files names be any?
Sir, in my case , I have scanned PDF files, I want to copy only a specific text from each page, Text sample xxxxx-xxx-xxx-IR-xxxxx I know only IR is fix on each page, before and after IR I don't know what is the text, but I want to copy all together from each page. Please help. If you and VBA macro please share. Or any other tools. Thanks
Hello, I have an error : Traceback (most recent call last): File "C:\Users\milad\PycharmProjects\pythonProject5\main.py", line 6, in for file_name in os.listdir('all_format_pdf'): FileNotFoundError: [WinError 3] The system cannot find the path specified: 'all_format_pdf' how can I fixed?
Sir I have one question,please answer me. I have pdf in regional language like hindi,marathi and font in pdf are not in unicode,then how can i extract data in excel from pdf.I need that pdf data in unicode within excel. Example:- Pdf file like voter lists in regional languages. Please answer me as i am trying all the time but all things are disapointing me. Thanks in advance
@@Python2020 hi there is some confidential data that I can't share, however I can brief my problem to you suppose I have three pdfs which constitute the details of students in a tabular format having the same schema but each of the pdf is from different institute. So, I want to extract the data present in the table from all three pdfs to an excel sheet using python. Kindly help me.
Ok, in this I m already storing data into variables..you have to break star and end of table...Next is how to write data in cells for that watch video no 5
for file_name in os.listdir('BAML'): print(file_name) #Loop on Files load_pdf = open(r'M:\Public Trade Operation\\Middle Office Package\\2023\\01 January\\Trade Confirmation\\US trades\\BAML\\'+file_name, 'rb') read_pdf = PyPDF2.PdfReader(load_pdf) #Load All Pdf in Variable page_count = len(read_pdf.pages) #Count the pdf pages first_page = read_pdf.pages[0] #read only the first page page_content = first_page.extract_text() #extract string output page_content = page_content.replace(' ','') print(page_content) Hello, I have multiple pdf in the folder, it did show all the pdf name when i print(file_name) However, it only print the content of the first pdf rather than all of them Would you please take a look, thx a lot
I have another question please, how can i extract all pdf pages not only the first page ? Because some of my pdf files have like 14 pages, so how should i extract all of them ?
For table there is a different approch.. You have to identify some keyword in the start of table and end of table... In between you need to run the loop
@@Python2020 this error i got line 7, in read_pdf = PyPDF2.PdfFileReader(load_pdf) in read stream.seek(-1, 2) AttributeError: 'tuple' object has no attribute 'seek'
Bro I've done exactly like you and installed the libraries required, but there's an error popping up in line 4 ( for file_name in os.Listdir('.........') ) The error is: FileNotFoundError: [WinError 3] The system cannot find the path spacified: '....' Do you have any solution might help please ?
Code is correct only check below.. It's complete folder path in os.Listdir ... Pdf file should be there in the folder ... Pdf should be text not scanned
@@Python2020 Yeah the code is correct sure, even I run another code so simple code just to open a random file in python but I'm getting the same error always (FileNotFoundError...) Not for pdf files only, nah also for text, normal text files, same error.. I'm using pycharm too, really IDK what's exactly the problem I have thousands of pdf files scanned and not scanned, I need to extract the data from them and write it to excel, but can't do anything because of this error...
@@Python2020 finally I found the solution, it's because wrong path, I run ( os.chdir ) to change the path then I put the path of my pdf files and it works, anyway thank you man for your time 👍🏻
Hi Harish, I have explained the code in the video, if you have doubt at any point mention the time and question... I dont keep files saved... Let me know if you face any error or so
My last question 😁 I'm trying to extract this data from the pdf files into just 2 columns in excel, first column is the pdf file names and second column is the text what I have extracted for each pdf file name, I used your method in the video but it only works for the pdf file names in column 1 and second column for the text what I extracted no, always when I run the code for both columns it pops up long error [ Traceback ( most recent call last): ........... in check_string raise IllegalCharacterError openpyxl.utils.exceptions.IllegalCharacterError ] And when I run the code just for the first column, it works well and it writes the pdf file names in the first column in excel. l just want to write the text what I have extracted for each pdf file in excel in column 2 I don't want to write specific details like names and addresses and mob no I want to write in excel the whole extracted pdf text, if you have any tips or solution for that please tell me and thank you so much 🤗
As per error, there should string encoding issu that is when illigal char error comes, you can try trim, or change encoding,, for fetching specific value you can use slicing or regex
hi sir, i have doubt, i need extract specified text like email -xxxxx@xxxx phone nos-(xxx)xxx-xxxx and name in a sheet and convert the data into excel or csv.wrote this program. plz help to solve . code mentioned below. import PyPDF2 import openpyxl import re import pytesseract as tess tess.pytesseract.tesseract_cmd=r"C:/Tesseract-OCR/tesseract.exe" from PIL import Image excel=openpyxl.Workbook() sheet=excel.active sheet.title='pdf' sheet.append(['phone number']) pdfFileObj = open('C:\Program Files\Python310/filename.pdf', 'rb') pdfReader = PyPDF2.PdfFileReader(pdfFileObj) num_pages = pdfReader.numPages count = 0 text = "" #The while loop will read each page. while count < num_pages: pageObj = pdfReader.getPage(count) count +=1 text += pageObj.extractText() text=text.replace(' ','') #print(text) print('---------') """
Thank you so much! I've broke my brain till was solving such task.
☺
Fantastic. Exactly what I am looking for. Thanks buddy! One quick question. I found you are using 3 PDF files for this demo which are named file1, file2, file3. Should the PDF names should be in some sequential order for iterating each files through loop or can the files names be any?
No, that is just for example, you can use any way to loop on each file in folder... And if you want you can sort files by different properties
Vedio for pypdf2 instalation because I have as issue which is download as file like word or internet explorer
can you please share the code used in this video ?
I have some problem my code can u debug where problem
How u installed pypdf2 in ur pc
No in python environment... Watch video 95 on my channel.. How to create new python environment
Sir, in my case , I have scanned PDF files, I want to copy only a specific text from each page,
Text sample xxxxx-xxx-xxx-IR-xxxxx
I know only IR is fix on each page, before and after IR I don't know what is the text, but I want to copy all together from each page.
Please help. If you and VBA macro please share. Or any other tools.
Thanks
There is another video on my channel.. Get Text from Scan pdf
@@Python2020sir specific text also ?
@@Python2020sir I searched but not found, please share link.
Here..czcams.com/video/Eg5pkNpYdmE/video.html
Hello, I have an error : Traceback (most recent call last):
File "C:\Users\milad\PycharmProjects\pythonProject5\main.py", line 6, in
for file_name in os.listdir('all_format_pdf'):
FileNotFoundError: [WinError 3] The system cannot find the path specified: 'all_format_pdf'
how can I fixed?
Give complete path
Sir I have one question,please answer me.
I have pdf in regional language like hindi,marathi and font in pdf are not in unicode,then how can i extract data in excel from pdf.I need that pdf data in unicode within excel.
Example:- Pdf file like voter lists in regional languages.
Please answer me as i am trying all the time but all things are disapointing me.
Thanks in advance
You can intall fonts for local languages use that in the text... You need to reach to get the proper text output,, then regex concept remains same
Hi can you please tell me is it possible to extract table of similar structures in different pdfs to an excel sheet using python
Can share sample on hiteshb0101@gmail.com
@@Python2020 hi there is some confidential data that I can't share, however I can brief my problem to you suppose I have three pdfs which constitute the details of students in a tabular format having the same schema but each of the pdf is from different institute. So, I want to extract the data present in the table from all three pdfs to an excel sheet using python. Kindly help me.
Ok, in this I m already storing data into variables..you have to break star and end of table...Next is how to write data in cells for that watch video no 5
for file_name in os.listdir('BAML'):
print(file_name) #Loop on Files
load_pdf = open(r'M:\Public Trade Operation\\Middle Office Package\\2023\\01 January\\Trade Confirmation\\US trades\\BAML\\'+file_name, 'rb')
read_pdf = PyPDF2.PdfReader(load_pdf) #Load All Pdf in Variable
page_count = len(read_pdf.pages) #Count the pdf pages
first_page = read_pdf.pages[0] #read only the first page
page_content = first_page.extract_text() #extract string output
page_content = page_content.replace('
','')
print(page_content)
Hello, I have multiple pdf in the folder, it did show all the pdf name when i print(file_name)
However, it only print the content of the first pdf rather than all of them
Would you please take a look, thx a lot
You need to get all pages in list and then loop on each page.. Add code in loop bosy
Can u provide some example
I am new to python not quite familiar about it
do we need install pre-requisites before. please share how
Yes we have to... Check video no 95 for installing python library
When running the code at @2.39 I got a syntax error for for file_name. Any idea why? Im using Jupyter Notebook.
Share full line of your code
@@Python2020 Hi, nevermind. The error was because I have not installed the module for pypdf2
I have another question please, how can i extract all pdf pages not only the first page ? Because some of my pdf files have like 14 pages, so how should i extract all of them ?
There is a line where I have mentioned zero from there you hv to include a loop after getting count of pages
@@Python2020 thank you it works 👍🏻❤️
Anyone knows, how to convert excel file sheets into pdf format using python.
On my channel there is macro code may work for you
Sir, I want to remove header, footer from every pages. Could you please help me?
You can create new pdf... First extract the data from existing one and use that data to write new pdf... Refer video no 12 on my channel
Sir I want extract text fields and below table also, can we do that?
For table there is a different approch.. You have to identify some keyword in the start of table and end of table... In between you need to run the loop
@@Python2020 I need specific column or specific row.as user want.
Use counter inside the loop... Or you can skip the column by identifying the text... It's a complax logic I know
I am getting an error "zipfile.badzipfile:file is not a zip file" can you pease help me
Your file might be scanned one... Copy text manually and see if you are able to selcet paste on notepad
i am getting that error when tired to run the script ( 'tuple' object has no attribute 'seek')
Check last line of the error, copy paste last 2 lines in Google... Or post the line of code which is causing error
@@Python2020 this error i got
line 7, in
read_pdf = PyPDF2.PdfFileReader(load_pdf)
in read
stream.seek(-1, 2)
AttributeError: 'tuple' object has no attribute 'seek'
@@rajasekharreddy.g3952 send me your file on hiteshb0101@gmail.com
@@Python2020 i sent file to your email
Can you pass full folder path in for loop and try... Just checked your mail in mobile
are you on fiverr ???
No
Bro I've done exactly like you and installed the libraries required, but there's an error popping up in line 4 ( for file_name in os.Listdir('.........') )
The error is: FileNotFoundError: [WinError 3] The system cannot find the path spacified: '....'
Do you have any solution might help please ?
Code is correct only check below.. It's complete folder path in os.Listdir ... Pdf file should be there in the folder ... Pdf should be text not scanned
Your error is relates to os. Listdir... Check in Google --iterate over pdf files in a folder using python
@@Python2020 Yeah the code is correct sure, even I run another code so simple code just to open a random file in python but I'm getting the same error always (FileNotFoundError...) Not for pdf files only, nah also for text, normal text files, same error..
I'm using pycharm too, really IDK what's exactly the problem
I have thousands of pdf files scanned and not scanned, I need to extract the data from them and write it to excel, but can't do anything because of this error...
@@Python2020 finally I found the solution, it's because wrong path, I run ( os.chdir ) to change the path then I put the path of my pdf files and it works, anyway thank you man for your time 👍🏻
Can you please send me the code sir.
Hi Harish, I have explained the code in the video, if you have doubt at any point mention the time and question... I dont keep files saved... Let me know if you face any error or so
My last question 😁 I'm trying to extract this data from the pdf files into just 2 columns in excel, first column is the pdf file names and second column is the text what I have extracted for each pdf file name, I used your method in the video but it only works for the pdf file names in column 1 and second column for the text what I extracted no, always when I run the code for both columns it pops up long error
[ Traceback ( most recent call last):
...........
in check_string raise IllegalCharacterError
openpyxl.utils.exceptions.IllegalCharacterError ]
And when I run the code just for the first column, it works well and it writes the pdf file names in the first column in excel.
l just want to write the text what I have extracted for each pdf file in excel in column 2 I don't want to write specific details like names and addresses and mob no I want to write in excel the whole extracted pdf text, if you have any tips or solution for that please tell me and thank you so much 🤗
As per error, there should string encoding issu that is when illigal char error comes, you can try trim, or change encoding,, for fetching specific value you can use slicing or regex
@@Python2020 alright thank you 🙏🏻
hi sir, i have doubt, i need extract specified text like email -xxxxx@xxxx phone nos-(xxx)xxx-xxxx and name in a sheet and convert the data into excel or csv.wrote this program. plz help to solve . code mentioned below.
import PyPDF2
import openpyxl
import re
import pytesseract as tess
tess.pytesseract.tesseract_cmd=r"C:/Tesseract-OCR/tesseract.exe"
from PIL import Image
excel=openpyxl.Workbook()
sheet=excel.active
sheet.title='pdf'
sheet.append(['phone number'])
pdfFileObj = open('C:\Program Files\Python310/filename.pdf', 'rb')
pdfReader = PyPDF2.PdfFileReader(pdfFileObj)
num_pages = pdfReader.numPages
count = 0
text = ""
#The while loop will read each page.
while count < num_pages:
pageObj = pdfReader.getPage(count)
count +=1
text += pageObj.extractText()
text=text.replace('
','')
#print(text)
print('---------')
"""
"""
phone = re.findall('\(\d{3}\)\d{3}-\d{4}', text)
#print(phone)
zip_code=re.findall('\d{5}',text)
my_zip=set(zip_code)
#print(my_zip)
email=re.findall('@*?\.',text)
print (email)
sheet.append(['phone','zip_code'])
excel.save('C:\Program Files\Python310/file.xlsx')
print('DONE!!')
After reading pdf use reqular expressions, use variable to append data in cav
@@Python2020 not able to understand some example plz