Table des matières

PDF avec pdfkit et wkhtmltopdf

pdfkit utilise wkhtmltopdf pour convertir du HTML en PDF.

Doc: https://pypi.org/project/pdfkit/

Installation de wkhtmltopdf

Sous Linux :

sudo apt install wkhtmltopdf

Sous Windows :

Installation de pdfkit

(venv) $ pip install pdfkit

Usage

Transformation d'un fichier test.html en test.pdf :

import pdfkit
 
pdfkit.from_file('/home/marc/test.html', '/home/marc/test.pdf')

Même chose à partir d'une chaîne de caractères :

import pdfkit
 
pdfkit.from_string('<h1>Hello World!</h1>', '/home/marc/test.pdf')