Ketan
Ketan

Reputation: 1

How to convert an excel sheet to a pdf using python?

I have an excel sheet which i want to convert to Python. Need recommendation in suggesting package or a module for above query.

i have tried with PDFWriter. I am using pandas to read my excel file and inputing that dataset to PDFwriter to create pdf file. The output pdf seems blank.

import pandas as pd
from pdfrw import PdfWriter

wb = pd.read_excel('excel file path')

wb=PdfWriter()

wb.write('result.pdf')

The pdf file created in of 1kb only..

Upvotes: 0

Views: 20437

Answers (2)

Nematillo Ochilov
Nematillo Ochilov

Reputation: 370

import pandas as pd
import pdfkit
df = pd.read_excel("file.xlsx")#input
df.to_html("file.html")#to html
pdfkit.from_file("file.html", "file.pdf")#to pdf

Upvotes: 1

Deepak Patankar
Deepak Patankar

Reputation: 3272

Here are few points :

  1. You are reading the DataFrame in a variable wb in first line and overwriting the same variable in next line. The values read from the excel sheet will be lost.
  2. You have to use addpage() function to add content to your page.

You can also try this link.

Upvotes: -1

Related Questions