|
@@ -7,6 +7,7 @@ import pythoncom
|
|
|
from upload_to_oss import TedOSS
|
|
|
import threading
|
|
|
import shutil
|
|
|
+from win32com.client.dynamic import Dispatch, ERRORS_BAD_CONTEXT
|
|
|
|
|
|
class DocxConverter(object):
|
|
|
"""
|
|
@@ -27,7 +28,7 @@ class DocxConverter(object):
|
|
|
imgfile = os.path.join(imgdir,file)
|
|
|
ossfile = uuidhtml+".files/"+file
|
|
|
self.oss.upload_from_local(imgfile,ossfile)
|
|
|
- shutil.rmtree(imgdir)
|
|
|
+ #shutil.rmtree(imgdir)
|
|
|
pythoncom.CoUninitialize()
|
|
|
|
|
|
def docx2html(self):
|
|
@@ -38,8 +39,26 @@ class DocxConverter(object):
|
|
|
self.word.Visible = 0
|
|
|
self.doc = self.word.Documents.Open(self.docpath)
|
|
|
self.uuidhtml = str(uuid.uuid4())
|
|
|
+ #html = os.path.join(os.path.dirname(self.docpath),self.uuidhtml+".html")
|
|
|
+ pdffile = os.path.join(os.path.dirname(self.docpath),self.uuidhtml+".pdf")
|
|
|
+ self.doc.SaveAs(pdffile,17)
|
|
|
html = os.path.join(os.path.dirname(self.docpath),self.uuidhtml+".html")
|
|
|
- self.doc.SaveAs(html,10)
|
|
|
+
|
|
|
+ from win32com.client.dynamic import Dispatch, ERRORS_BAD_CONTEXT
|
|
|
+
|
|
|
+ AvDoc = Dispatch("AcroExch.AVDoc")
|
|
|
+ try:
|
|
|
+ if AvDoc.Open(pdffile,""):
|
|
|
+ pdDoc = AvDoc.GetPDDoc()
|
|
|
+ jsObject = pdDoc.GetJSObject()
|
|
|
+ jsObject.SaveAs(html,"com.adobe.acrobat.html")
|
|
|
+ except Exception as e:
|
|
|
+ import traceback
|
|
|
+ traceback.print_exc()
|
|
|
+ AvDoc.close(True)
|
|
|
+ finally:
|
|
|
+ AvDoc.Close(True)
|
|
|
+
|
|
|
self.doc.Close()
|
|
|
self.word.Quit()
|
|
|
os.remove(self.docpath)
|