incuna / django-wkhtmltopdf

Django Wrapper to the PDF Renderer: wkhtmltopdf
BSD 2-Clause "Simplified" License
326 stars 155 forks source link

add background: pipe output of wkhtml to pdftk #147

Open benjaminderei opened 7 years ago

benjaminderei commented 7 years ago

how to subclass PDFTemplateView to add another subprocess call and pipe the ouput of wkhtmltopdf to pdftk (pdftk - background background.pdf output -) ?

notanumber commented 6 years ago

I've done this in my fork I think with a little bit of work it could be cleaned up and possibly merged into the project but would introduce a dependency on PDFTK. I also removed the old subprocess.py module in my fork as I'm not interested in Python versions older than 2.7, but there's no reason it couldn't be re-inserted.

As-is, you can use it by setting background_template to the template you'd like to use as the background. Personally, I have something like:

{% extends 'print.html' %}
{% load staticfiles %}
{% block content %}
<div class="watermark">
    <img class="watermark-logo" src="{% static 'img/logo.png' %}">
</div>
{% endblock %}

This is working great for me. If anyone has suggestions on how this can be improved in order to be useful for anyone else, let me know.