gpt4 book ai didi

python - 在没有 pdfkit 的情况下将 Pandas DataFrame 保存为 PDF 文件格式

转载 作者:太空宇宙 更新时间:2023-11-03 13:58:42 25 4
gpt4 key购买 nike

我想将 pandas dataframe 保存为 pdf 格式。

import pdfkit as pdf    
config = pdf.configuration(wkhtmltopdf="C:\Program Files\wkhtmltopdin\wkhtmltopdf.exe")
pdf.from_url('http://google.com', 'out.pdf',configuration=config)
--> not working somehow even though I downloaded wkhtmltopdin on several different locations

from weasyprint import HTML
HTML(string=pd.read_csv('cor.csv').to_html()).write_pdf("report.pdf")

dlopen() failed to load a library: cairo / cairo-2 / cairo-gobject-2
--> not working : Tried several times to solve this isseue, but cannot download library

在stackoverflow等网站上又试了5个包和方法都解决不了。

有没有更多的套餐可以让我多试试?这让我得了癌症

提前致谢。

最佳答案

一种选择是从以下开始:

df.to_html()

然后使用QT将HTML转PDF如下:

from PyQt4.QtGui import QTextDocument, QPrinter, QApplication

import sys
app = QApplication(sys.argv)

doc = QTextDocument()
location = "c://apython//Jim//html//notes.html"
html = open(location).read()
doc.setHtml(html)

printer = QPrinter()
printer.setOutputFileName("foo.pdf")
printer.setOutputFormat(QPrinter.PdfFormat)
printer.setPageSize(QPrinter.A4)
printer.setPageMargins(15, 15, 15, 15, QPrinter.Millimeter)

doc.print_(printer)
print("done!")

我从 html to pdf 获得了第二位代码,并在 Mac OSX 上进行了测试,结果良好。

关于python - 在没有 pdfkit 的情况下将 Pandas DataFrame 保存为 PDF 文件格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51973991/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com