Python 将用户创建的函数输出导出为pdf

Python 将用户创建的函数输出导出为pdf,python,plotly,Python,Plotly,我有一个长函数,其中包含多个字符串和HTML图形(使用Plotly)。我想知道是否有可能以编程方式将其输出导出为pdf格式的电子邮件报告。下面是函数的示例: import numpy as np import plotly.graph_objs as go from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot x = np.random.randn(2000) y = np.random.ra

我有一个长函数,其中包含多个字符串和HTML图形(使用Plotly)。我想知道是否有可能以编程方式将其输出导出为pdf格式的电子邮件报告。下面是函数的示例:

import numpy as np
import plotly.graph_objs as go
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot

x = np.random.randn(2000)
y = np.random.randn(2000)

def function():
    print('this is a string')
    iplot([go.Histogram2dContour(x=x, y=y, contours=dict(coloring='heatmap')),
       go.Scatter(x=x, y=y, mode='markers', marker=dict(color='white', size=3, opacity=0.3))], show_link=False)
由于函数包含一个字符串和一个HTML图形,python将其存储为“nonetype”,因此,我通常使用PDFkit
from_string
解决此问题的方法在这种情况下不起作用


有人知道我可以通过编程方式将function()的输出下载到pdf的方法吗

?@AMC我让Orca工作,但此方法不接受函数。