AvDoc

2021-05-31  本文已影响0人  月夜星空下
import os
import winerror
from win32com.client.dynamic import Dispatch, ERRORS_BAD_CONTEXT

ERRORS_BAD_CONTEXT.append(winerror.E_NOTIMPL)

my_dir = r"C:\\path\\to\\example\\"
my_pdf = "example.PDF"

os.chdir(my_dir)
src = os.path.abspath(my_pdf)

try:
    AvDoc = Dispatch("AcroExch.AVDoc")

    if AvDoc.Open(src, ""):
        pdDoc = AvDoc.GetPDDoc()
        jsObject = pdDoc.GetJSObject()
        jsObject.SaveAs(os.path.join(my_dir, 'output_example.xml'), "com.adobe.acrobat.xml-1-00")

except Exception as e:
    print(str(e))

finally:
    AvDoc.Close(True)

    jsObject = None
    pdDoc = None
    AvDoc = None
上一篇下一篇

猜你喜欢

热点阅读