[Python][Adobe Acrobat] Save PDF as Excel problem
Question:
I am working on converting PDF to Excel by adobe acrobat Pro and Python. Recently, the program can open adobe acrobat but it can save the pdf as excel file. Acrobat pop up an error message
The specified file could not be written to. It may be in use.
I have no idea what is problem.
import win32com.client, win32com.client.makepy, os, winerror, pandas as pd, errno, re
from win32com.client.dynamic import ERRORS_BAD_CONTEXT
class Acrobat_scan_automation:
def __init__(self):
self.directory_path = r'D:DesktopDesktop_21.Python_projectACROBAT_SCAN_AUTOMATION'
os.chdir(self.directory_path)
self.folder_name = {
"output": r'output',
"source": r'source',
}
self.excel_file = r'output.xlsx'
self.output_csv = r'output_1.csv'
self.pdf_file = r'arabic.pdf'
return
def pdf2excel(self,pdf_file,excel_file):
try:
ERRORS_BAD_CONTEXT.append(winerror.E_NOTIMPL)
src = os.path.abspath(os.path.join(self.folder_name['source'],pdf_file))
print('[INFO] abspath=',src)
win32com.client.makepy.GenerateFromTypeLibSpec('Acrobat')
adobe = win32com.client.DispatchEx('AcroExch.App')
avDoc = win32com.client.DispatchEx('AcroExch.AVDoc')
print('[INFO] Open',src)
avDoc.Open(src, src)
pdDoc = avDoc.GetPDDoc()
print('[INFO] pdDoc=',pdDoc)
jsObject = pdDoc.GetJSObject()
print('[INFO] jObject=',jsObject)
export_file = os.path.abspath(os.path.join(self.folder_name['output'],excel_file))
jsObject.SaveAs(export_file, 'com.adobe.acrobat.xlsx') # < ---- Error
except Exception as e:
print(str(e))
finally:
# avDoc.Close(True)
jsObject = None
pdDoc = None
avDoc = None
return
def main(self):
print('[INFO] Start using acrobat')
self.pdf2excel(self.pdf_file, self.excel_file)
return
if __name__ == '__main__':
Program = Acrobat_scan_automation()
Program.main()
Answers:
I re-install adobe acrobat to solve this issue.
I am working on converting PDF to Excel by adobe acrobat Pro and Python. Recently, the program can open adobe acrobat but it can save the pdf as excel file. Acrobat pop up an error message
The specified file could not be written to. It may be in use.
I have no idea what is problem.
import win32com.client, win32com.client.makepy, os, winerror, pandas as pd, errno, re
from win32com.client.dynamic import ERRORS_BAD_CONTEXT
class Acrobat_scan_automation:
def __init__(self):
self.directory_path = r'D:DesktopDesktop_21.Python_projectACROBAT_SCAN_AUTOMATION'
os.chdir(self.directory_path)
self.folder_name = {
"output": r'output',
"source": r'source',
}
self.excel_file = r'output.xlsx'
self.output_csv = r'output_1.csv'
self.pdf_file = r'arabic.pdf'
return
def pdf2excel(self,pdf_file,excel_file):
try:
ERRORS_BAD_CONTEXT.append(winerror.E_NOTIMPL)
src = os.path.abspath(os.path.join(self.folder_name['source'],pdf_file))
print('[INFO] abspath=',src)
win32com.client.makepy.GenerateFromTypeLibSpec('Acrobat')
adobe = win32com.client.DispatchEx('AcroExch.App')
avDoc = win32com.client.DispatchEx('AcroExch.AVDoc')
print('[INFO] Open',src)
avDoc.Open(src, src)
pdDoc = avDoc.GetPDDoc()
print('[INFO] pdDoc=',pdDoc)
jsObject = pdDoc.GetJSObject()
print('[INFO] jObject=',jsObject)
export_file = os.path.abspath(os.path.join(self.folder_name['output'],excel_file))
jsObject.SaveAs(export_file, 'com.adobe.acrobat.xlsx') # < ---- Error
except Exception as e:
print(str(e))
finally:
# avDoc.Close(True)
jsObject = None
pdDoc = None
avDoc = None
return
def main(self):
print('[INFO] Start using acrobat')
self.pdf2excel(self.pdf_file, self.excel_file)
return
if __name__ == '__main__':
Program = Acrobat_scan_automation()
Program.main()
I re-install adobe acrobat to solve this issue.