Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adobe Acrobat DC and Python automation

I want to automate something in by opening PDF file in Adobe Acrobat Pro DC and then using function that is available in that version to export all data in to excel spreadsheet.

Is there a way that I can have a script that opens the PDF file and exports all data in that file into an Excel sheet?

Is there maybe a way to Open PDF by pywin32 and then save file as Excel or CSV?

Here is the code I am trying to use but it does not work

import win32com.client
import win32com.client.makepy

win32com.client.makepy.GenerateFromTypeLibSpec('Acrobat')
adobe = win32com.client.DispatchEx('AcroExch.App')
avDoc = win32com.client.DispatchEx('AcroExch.AVDoc')
avDoc.Open('Input.pdf', 'C:\\Users\\PDF\\')
pdDoc = avDoc.GetPDDoc()
jObject = pdDoc.GetJSObject()
jObject.SaveAs('Output.xlsx', "com.adobe.acrobat.xlsx")
like image 923
Denis Morozov Avatar asked Mar 14 '26 20:03

Denis Morozov


1 Answers

Here is the anwser figured out by me:

import win32com.client, win32com.client.makepy, os, winerror, pandas as pd, errno, re
from win32com.client.dynamic import ERRORS_BAD_CONTEXT

excel_file = "output.xlsx"
output_1 = "output_1.csv"

ERRORS_BAD_CONTEXT.append(winerror.E_NOTIMPL)

src = os.path.abspath('FILE.pdf')

win32com.client.makepy.GenerateFromTypeLibSpec('Acrobat')
adobe = win32com.client.DispatchEx('AcroExch.App')
avDoc = win32com.client.DispatchEx('AcroExch.AVDoc')
avDoc.Open(src, src)
pdDoc = avDoc.GetPDDoc()
jObject = pdDoc.GetJSObject()
jObject.SaveAs(excel_file, "com.adobe.acrobat.xlsx")
like image 83
Denis Morozov Avatar answered Mar 17 '26 08:03

Denis Morozov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!