I am trying to generate a PDF file from a Folium map using the weasyprint package in Python. I have the following code:
import folium
from weasyprint import HTML
def generate_map_html(lat: float, lon: float):
"""
Generate a map HTML
"""
# Generate map
m = folium.Map(location=[lat, lon], zoom_start=15)
# Add marker
folium.Marker([lat, lon], popup='Property Location').add_to(m)
# Save map to html
map_html = m._repr_html_()
return map_html
map_location = generate_map_html(33.589886, -7.603869)
html = HTML(string=map_location)
# save html to pdf
pdf = html.write_pdf()
with open('out/output.pdf', 'wb') as f:
f.write(pdf)
The PDF file is generated successfully, but instead of the map, I see the text "Make this Notebook Trusted to load map: File -> Trust Notebook".
How can I fix this issue and get the map to display in the PDF output?