pvanand commited on
Commit
b32973f
·
verified ·
1 Parent(s): e705ada

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +21 -1
main.py CHANGED
@@ -87,4 +87,24 @@ async def get_realtime_trending_searches(pn: str = Query('US', description="Coun
87
 
88
  @app.get("/", tags=["Home"])
89
  def api_home():
90
- return {'detail': 'Welcome to Web-Scraping API! Visit https://pvanand-web-scraping.hf.space/docs to test'}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
 
88
  @app.get("/", tags=["Home"])
89
  def api_home():
90
+ return {'detail': 'Welcome to Web-Scraping API! Visit https://pvanand-web-scraping.hf.space/docs to test'}
91
+
92
+ class HTMLRequest(BaseModel):
93
+ html_content: str
94
+
95
+ @app.post("/convert-to-pdf")
96
+ async def convert_to_pdf(request: HTMLRequest):
97
+ try:
98
+ options = {
99
+ 'page-size': 'A4',
100
+ 'margin-top': '0.75in',
101
+ 'margin-right': '0.75in',
102
+ 'margin-bottom': '0.75in',
103
+ 'margin-left': '0.75in',
104
+ 'encoding': "UTF-8",
105
+ }
106
+
107
+ pdf = pdfkit.from_string(request.html_content, False, options=options)
108
+ return Response(content=pdf, media_type="application/pdf")
109
+ except Exception as e:
110
+ raise HTTPException(status_code=500, detail=str(e))