简体   繁体   中英

Converting (ideally) doc to pdf with python or docx to pdf, but I get error

I am working in ios and with spyder (anaconda) trying the following code in order to convert docx files which are in a directory (folder_path):

from docx2pdf import convert
import os

no_pdfs = []
i=1
for filename in os.listdir(os.path.normcase(folder_path)):
    filename = os.path.join(folder_path, filename)

    try:
        convert(filename, os.path.splitext(filename)[0]+'.pdf')
        print(f"DONE - {i}: {os.path.basename(filename)}")
        i += 1
    except Exception:
        no_pdfs.append(os.path.basename(filename))

print(no_pdfs)

I use try - except in my code because there is the.DS_Store that appears with ios and nothing happens. If I brutally try convert() I get the error: ImportError: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html ImportError: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html ImportError: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html but I am not really able to understand what goes wrong.

An extra thing is that my initial files are not actually.docx but.doc and I would really like a piece of advice where I could convert doc to pdf or doc to docx to pdf.

Any help will be much appreciated!

If you haven't resolved this yet, you could try installing the Parallels Access from the Apple store on your ios but it sounds like you just have to update your packages (pip install --upgrade PackageName). The code you provided might be working, but the error is being flagged from those packages you mentioned. Also with docx2pdf, have you installed word on your device? From the creator of docx2pdf "Unfortunately, it requires Microsoft Office to be installed and thus only works on Windows and macOS. – Al Johri" Also, An efficient way to convert document to pdf format is worth reading.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM