Convert EMF/WMF files to PNG/JPG

后端 未结 4 830
深忆病人
深忆病人 2021-02-14 10:23

I am receiving an form upload with a Word docx document. I got all the parsing done successfully. I have to then display that Word document on the web.

The problem I am

4条回答
  •  生来不讨喜
    2021-02-14 10:45

    I found it easier to use the Wand package for such conversion. I tried the previous suggestions without success. So here is what I did: (BTW, I wanted to convert all '.wmf' files into pdf)

    import os
    
    from wand.image import Image as wima
    
    folder='C:/Users/PythonLover/Pictures/pics'
    
    for oldfilename in os.listdir(folder):
    
        if oldfilename.endswith(".wmf"):
    
            with wima(filename=folder+'/'+oldfilename) as img:
    
                newfilename = oldfilename.split('.')[0]+'.pdf'
    
                newfilename = folder+'/'+newfilename
    
                img.format = 'pdf'
    
                img.save(filename=newfilename)
    

提交回复
热议问题