简体   繁体   English

使用 pdfkit 使用 python 创建 pdf 文件

[英]creating pdf file with python using pdfkit

I am trying to use pdfkit module on python to create pdf file from text.我正在尝试在 python 上使用 pdfkit 模块从文本创建 pdf 文件。 the first time I ran the following code, it was alright, but after the second attempt the background of the created file is dark, I tried to write this code into a different file and execute it but the result is the same.我第一次运行下面的代码,没问题,但是第二次尝试创建文件的背景是黑暗的,我试图将这段代码写入另一个文件并执行它,但结果是一样的。 Would somebody please show me how to fix it.有人请告诉我如何解决它。 Thanks.谢谢。

This is the code I tried to test the pdfkit:这是我尝试测试 pdfkit 的代码:

#!/usr/bin/python3 
import pdfkit
pdfkit.from_string('MicroPyramid', 'micro_2.pdf')

If you can use a different library, try pdfme .如果您可以使用其他库,请尝试pdfme It's the most powerful library in python to create PDF documents.它是 python 中最强大的库,用于创建 PDF 文档。

from pdfme import buid_pdf

with open('micro_2.pdf', 'wb') as f:
    build_pdf({'sections': [{'content': ['MicroPyramid']}]})

Check the docs here此处查看文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM