0

I'm running a python script on a windows laptop to convert some sample pdf files to docx. However, for each file, a dialog box pops up that prompts me to click OK when the script tries to convert said file to docx. Any idea how I might suppress this popup or configure the script so that no click action is needed from the user?

Code:

import win32com.client #open win32 client in hidden mode word = win32com.client.Dispatch("Word.Application") word.Visible = False word.DisplayAlerts = False #tried setting this to False and 0 to suppress dialog. didn't work pdf_path = r"C:\path\to\pdf" doc_path = r"C:\path\to\docx" #open pdf doc with client pdf_doc = word.Documents.Open(pdf_path) #convert pdf to docx pdf_doc.SaveAs2(doc_path, FileFormat=16) #16 is the file format for docx. tried running this with pdf_doc.SaveAs. didn't work. pdf_doc.Close() #also tried running this as pdf_doc.Close(False). didn't work word.Quit() 

Dialog popup

1
  • I think it's the Office version. I tried your code with my Word 2010 and didn't see any dialog, but the target file format was .doc Commented Mar 6 at 17:10

1 Answer 1

0

Changing

pdf_doc = word.Documents.Open(pdf_path) 

to

pdf_doc = word.Documents.Open(pdf_path, False, False, False) 

fixed the issue for me.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.