To configure PDFkit on Windows for Python, you can follow these steps:
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.
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.