{"id":2185,"library":"pdfkit","title":"pdfkit","description":"pdfkit is a Python wrapper for `wkhtmltopdf`, a command-line tool that renders HTML content into PDF documents using the WebKit engine. It provides an easy-to-use API to convert HTML from URLs, local files, or raw strings into PDF. While the `pdfkit` library itself is at version 1.0.0, its core dependency, `wkhtmltopdf`, was archived in January 2023, meaning `pdfkit` relies on an unmaintained external tool.","status":"maintenance","version":"1.0.0","language":"en","source_language":"en","source_url":"https://github.com/JazzCore/python-pdfkit","tags":["pdf","html-to-pdf","wkhtmltopdf","document-generation","wrapper","html"],"install":[{"cmd":"pip install pdfkit","lang":"bash","label":"Install Python package"},{"cmd":"sudo apt-get install wkhtmltopdf","lang":"bash","label":"Debian/Ubuntu (limited features)"},{"cmd":"brew install homebrew/cask/wkhtmltopdf","lang":"bash","label":"macOS"},{"cmd":"Download installer from wkhtmltopdf.org and add to PATH","lang":"bash","label":"Windows (recommended)"}],"dependencies":[{"reason":"External command-line tool required for HTML to PDF conversion. It must be installed separately and be accessible in the system's PATH.","package":"wkhtmltopdf","optional":false}],"imports":[{"symbol":"pdfkit","correct":"import pdfkit"}],"quickstart":{"code":"import pdfkit\nimport os\n\n# Ensure wkhtmltopdf is in your PATH or specify its path\n# config = pdfkit.configuration(wkhtmltopdf='/usr/local/bin/wkhtmltopdf')\n# For simplicity in quickstart, assumes wkhtmltopdf is in PATH.\n\nhtml_content = \"\"\"\n<!DOCTYPE html>\n<html>\n<head>\n    <meta charset=\"utf-8\">\n    <title>My PDF Document</title>\n    <style>\n        body { font-family: sans-serif; }\n        h1 { color: #333; }\n    </style>\n</head>\n<body>\n    <h1>Hello from PDFKit!</h1>\n    <p>This is a simple HTML string converted to a PDF.</p>\n    <p>Current directory: {}</p>\n</body>\n</html>\n\"\"\".format(os.getcwd())\n\noutput_filename = 'example.pdf'\npdfkit.from_string(html_content, output_filename)\nprint(f\"PDF generated: {output_filename}\")\n\n# Example from URL\n# pdfkit.from_url('http://google.com', 'google.pdf')\n\n# Example from file\n# with open('input.html', 'w') as f:\n#     f.write('<h1>Test File</h1>')\n# pdfkit.from_file('input.html', 'file.pdf')","lang":"python","description":"This quickstart demonstrates converting an HTML string to a PDF file. Ensure `wkhtmltopdf` is installed and its executable is discoverable in your system's PATH. For URLs or local files, use `pdfkit.from_url` or `pdfkit.from_file` respectively."},"warnings":[{"fix":"Be aware of the upstream status. For new projects, consider actively maintained alternatives like Playwright, WeasyPrint, or dedicated PDF generation APIs if long-term support is critical.","message":"The underlying `wkhtmltopdf` project, which `pdfkit` wraps, was archived in January 2023 and is no longer maintained. While `pdfkit` may still function with existing `wkhtmltopdf` binaries, this poses long-term risks for security, compatibility, and new feature development.","severity":"breaking","affected_versions":"All versions of pdfkit relying on wkhtmltopdf"},{"fix":"Install `wkhtmltopdf` separately (e.g., via `brew`, `apt-get`, or direct download for Windows) and ensure its executable's directory is included in your system's PATH. Alternatively, specify the full path to the `wkhtmltopdf` binary using `pdfkit.configuration(wkhtmltopdf='/path/to/wkhtmltopdf_binary')`.","message":"Common `IOError: 'No wkhtmltopdf executable found'` occurs if `wkhtmltopdf` is not installed or not in the system's PATH. `pdfkit` cannot function without it.","severity":"gotcha","affected_versions":"All"},{"fix":"For full functionality, download a static binary from the official `wkhtmltopdf.org` website instead of using `apt-get`.","message":"Installing `wkhtmltopdf` via `apt-get` on Debian/Ubuntu often provides a version with reduced functionality (compiled without QT patches). This version lacks features like outlines, headers, footers, and table of contents.","severity":"gotcha","affected_versions":"All"},{"fix":"Ensure your HTML content explicitly includes `<meta charset=\"utf-8\">` within the `<head>` section. Also, specify `encoding='UTF-8'` in `pdfkit` options if necessary.","message":"Non-ASCII characters (e.g., special symbols, accented letters) in HTML can lead to rendering issues or blank output in PDFs.","severity":"gotcha","affected_versions":"All"},{"fix":"To view `wkhtmltopdf`'s output for debugging purposes, pass `options={'enable-javascript': True, 'no-stop-slow-scripts': True}` or `verbose=True` to the `pdfkit.from_*` calls to disable the quiet mode or get detailed output.","message":"Starting with `pdfkit` version 1.0.0, the `--quiet` option is passed to `wkhtmltopdf` by default, suppressing its output to stdout/stderr. This can make debugging difficult.","severity":"breaking","affected_versions":"1.0.0 and later"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}