I'm looking for a way to convert word or excel file to pdf file using in my FastAPI project.
I tried to use comtypes
library but that didn't help. I guess this library is not what i exactly need
I got an error
ctypes.ArgumentError: argument 1: TypeError: Cannot put <starlette.datastructures.UploadFile object at 0x0000020CFF14E310> in VARIANT
main.py
import comtypes.client
app = FastAPI()
@app.post('/')
async def root(file: UploadFile = File(...)):
wdFormatPDF = 17
word = comtypes.client.CreateObject('Word.Application')
doc = word.Documents.Open(file)
doc.SaveAs(f'{file.filename}', FileFormat=wdFormatPDF)
doc.Close()
word.Quit()
return {'file_name': file.filename}