在不使用pdfkit的情况下将Pandas DataFrame保存为PDF文件格式 [英] Saving Pandas DataFrame into PDF File format without pdfkit

查看:192
本文介绍了在不使用pdfkit的情况下将Pandas DataFrame保存为PDF文件格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将熊猫数据框保存为pdf格式.

I want to save a pandas dataframe into pdf format.

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个以上的软件包和方法,但无法解决.

I have tried 5 more packages and methods in stackoverflow and other websites but could not solve it.

我还有更多可以尝试的软件包吗?这让我得了癌症

Is there any more packages that I can try more? this giving me a cancer

谢谢.

推荐答案

一个选择是开始于:

df.to_html()

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

and then use QT to convert the HTML to PDF as follows:

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转换为pdf中获得了第二部分代码,并在Mac OSX上进行了测试,取得了积极的成果.

I obtained the second bit of code from html to pdf, and tested on Mac OSX with positive results.

这篇关于在不使用pdfkit的情况下将Pandas DataFrame保存为PDF文件格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆