Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (16.4k points)
closed by

I began to learn python as of late and I need to change over the current HTML document to pdf record. It is exceptionally weird, however, pdfkit is by all accounts the just lib for pdf docs for python. 

import pdfkit

pdfkit.from_file("C:\\Users\\user\Desktop\\table.html", "out.pdf")

But, I get an error:

OSError: No wkhtmltopdf executable found: "b''"

How to arrange this lib appropriately on windows to make it work? I can't get it :(

closed

3 Answers

0 votes
by (25.7k points)
selected by
 
Best answer

To configure PDFkit on Windows for Python, you can follow these steps:

  1. Install wkhtmltopdf:

    • Go to the wkhtmltopdf downloads page: https://wkhtmltopdf.org/downloads.html
    • Scroll down to the section for Windows and download the installer for your system (32-bit or 64-bit).
    • Run the installer and follow the installation instructions.
  2. Install the PDFkit library:

    • Open your command prompt or terminal.
    • Run the following command to install PDFkit using pip:

pip install pdfkit

3. Configure PDFkit to use the wkhtmltopdf executable:

import pdfkit 

pdfkit.configuration(wkhtmltopdf='C:/Program Files/wkhtmltopdf/bin/wkhtmltopdf.exe') 

  • Locate the installation path of wkhtmltopdf. By default, it is installed in "C:\Program Files\wkhtmltopdf" on Windows.
  • Set the path to the wkhtmltopdf executable using the configuration() function from PDFkit. Add the following code at the beginning of your Python script:

Make sure to adjust the path based on your installation location if it differs.

4. Test PDFkit:

  • You can now use PDFkit in your Python code to convert HTML to PDF. Here's an example:

import pdfkit 

# Example usage 

pdfkit.from_file('input.html', 'output.pdf')

Replace 'input.html' with the path to your HTML file, and 'output.pdf' with the desired output PDF file path.

By following these steps, you should be able to configure and use PDFkit with wkhtmltopdf on Windows for PDF generation in Python.

    0 votes
    by (26.4k points)
    edited by

    To configure PDFkit on Windows for Python, follow these steps:

    1. Download and install wkhtmltopdf from the official website.
    2. Use pip to install the PDFkit library.
    3. Set the path to the wkhtmltopdf executable using pdfkit.configuration().
    4. Test PDFkit by converting HTML to PDF using the pdfkit.from_file() function.

    By following these steps, you will successfully configure PDFkit with wkhtmltopdf on Windows for PDF generation in Python.

    0 votes
    by (15.4k points)

    To configure PDFkit on Windows for Python:

    1. Install wkhtmltopdf from the official website.
    2. Use pip to install the PDFkit library.
    3. Set the path to the wkhtmltopdf executable using pdfkit.configuration().
    4. Test PDFkit by using the pdfkit.from_file() function to convert HTML to PDF.

    By following these steps, you can configure and use PDFkit with wkhtmltopdf on Windows for PDF generation in Python.

    1.2k questions

    2.7k answers

    501 comments

    693 users

    Browse Categories

    ...