pdfkit 使用 from_string 创建页面

Hea*_*run 7 python pdfkit python-pdfkit

我正在使用 pdfkit 从字符串生成 pdf 文件。

问:我传递给 pdfkit 的每个字符串我都希望它作为输出 pdf 中的一个新页面。

我知道使用如下 from_file 是可能的。但是,我不想将它写入文件并使用它。

pdfkit.from_file(['file1', 'file2'], 'output.pdf') 这将创建 2 页的 output.pdf 文件。

类似下面的东西可能吗?

pdfkit.from_string(['ABC', 'XYZ'], 'output.pdf') 
Run Code Online (Sandbox Code Playgroud)

它应该在 output.pdf 文件的第 1 页和第 2 页中写“ABC”和“XYZ”

小智 -4

您可以像这样连接字符串:

pdfkit.from_string('ABC' + 'XYZ', 'output.pdf')
Run Code Online (Sandbox Code Playgroud)