Creating PDF of streamlit website

we have seen that pdfkit and other different libraries arent supporting streamlit website to generate pdf as there is also one thing that i dont want to create pdf i want to generate automated pdf of my webpage when i click on button so i have used selenium to generate automated pdf of my webpage here is the code


from selenium import webdriver
import json

export_as_pdf = st.button(“Export Report”)

if export_as_pdf:
chrome_options = webdriver.ChromeOptions()
settings = {
“recentDestinations”: [{
“id”: “Save as PDF”,
“origin”: “local”,
“account”: “”,
“selectedDestinationId”: “Save as PDF”,
“version”: 2,
## automated formatting of pdf you can change accordingly
“isHeaderFooterEnabled”: False,
“isLandscapeEnabled”: True,
“scalingType”: 3,
“scaling”: “141”,
“Margins”: “Minimum”
prefs = {‘printing.print_preview_sticky_settings.appState’: json.dumps(settings)}
chrome_options.add_experimental_option(‘prefs’, prefs)
## that is my chrome driver path you can install it and give yours
CHROMEDRIVER_PATH = r"C:\Users\AI Engineer\chromedriver"
driver = webdriver.Chrome(chrome_options=chrome_options,
driver.get(“your website link”)
#i used time.sleep as my website was taking time to load so after getting url i letted it to
load then after it loads properly selenium will generate its pdf
thanks hope this hack works
you will find your pdf in downloads folder in your computer