I want to print watermark on the document when printed using pdfkit.
when manually printing from browser using ctrl+p ,the watermark is shown but not when printed using pdfkit.
My assumption is that pdfkit prints the document exactly as it is rendered on the monitor and to make pdfkit print the document exactly like how a browser would print it, would by settings the print-media-type flag in pdfkit's options.
As per https://wkhtmltopdf.org/usage/wkhtmltopdf.txt documentation,
--print-media-type Use print media-type instead of screen
--no-print-media-type Do not use print media-type instead of screen (default)
options for pdfkit, from my function:
_options = {
'cookie': [
('csrftoken', options.get('csrftoken','none')),
('sessionid', options.get('session_key','none')),
],
'footer-center': 'Page [page] of [topage]',
'footer-right': DOC_VERSION.get(doctype,''),
'footer-font-size': '9',
'print-media-type': ,
}
I've tried following combinations but none of them worked :
'print-media-type': 'True',
'print-media-type': True,
'print-media-type': '',
question : 1. is my assumption correct ? if yes, 2. how do i set this flag ?
This worked for me:
options = {
"disable-local-file-access": None,
"enable-local-file-access": None,
"print-media-type": None
}
pdfkit.from_file('index.html', 'out.pdf', options=options)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With