Create smaller pdfs with pdfkit
In my django project, i am creating pdfs in python using pdfkit library. However my pdfs with 15 pages have 16mb size.
my lib
pdfkit==1.0.0
How can I reduce its size, considering my code above:
import pdfkit
from django.template.loader import render_to_string
my_html = ''
for content in blocktexts:
my_html += render_to_string('mypath/myhtml.html')
pdfkit.from_string(my_html, False)
I loop in a variable called blocktexts that i have html contents in it and each one of them should create a pdf page, the problem is that each single page has 1mb, with only text in it and a small image in the begining...
How can I make this pdf smaller?
If pdfkit
does not meet your needs, you might explore other libraries like WeasyPrint
or xhtml2pdf
, which could offer better compression out-of-the-box.