Download PDF file using pdfkit and FastAPI
Returning FileResponse is solved my problem. Thanks to @Paul H and @clmno Below codes are working example of returning pdf file to download with FastApi. from typing import Optional from fastapi import FastAPI from starlette.responses import FileResponse import pdfkit app = FastAPI() config = pdfkit.configuration(wkhtmltopdf=r”C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe”) @app.get(“/”) def read_root(): pdfkit.from_url(“https://nakhal.expo.com.tr/nakhal/preview”,”file.pdf”, configuration=config) return FileResponse( “file.pdf”, media_type=”application/pdf”, … Read more