Watermark as background-image doesn't work / pisa + Django

1,600 views
Skip to first unread message

Ni

unread,
Oct 10, 2011, 5:26:36 PM10/10/11
to Pisa XHTML2PDF Support
Hi,
I'm new to pisa.
I want to return as a response pdf file - created using html (only
text, no images) with a watermark which I have as another pdf file.
Text formatting works fine, but I can't add the watermark. I've tried
following:

in html template:

<html xmlns:pdf="">
<head>
<meta http-equiv="content-type" content="text/html;
charset=UTF-8"/>
<style type="text/css">
@page {
background-image: url("../site_media/img/
watermark.pdf");
margin-left: 3cm;
margin-right: 3cm;
margin-top: 5cm;
margin-bottom: 4cm;

}
</style>
(...)


in views.py:
(...)
template = get_template('report.html')
data.update({'pagesize' : 'A4'})
context = Context(data)
html = template.render(context)
result = StringIO.StringIO()
pdf =
pisa.pisaDocument(StringIO.StringIO( html.encode("ISO-8859-13")),
result, encoding="ISO-8859-13")
response = http.HttpResponse(result.getvalue(),
mimetype='application/pdf')
import re
response['Content-Disposition'] = 'attachment; filename=' +
re.sub(r'\s', '', inquiry.name) + '_raport.pdf'

return response

sebastiaan

unread,
Oct 25, 2011, 5:46:28 AM10/25/11
to Pisa XHTML2PDF Support
Hi,

I had a simmilar problem some time ago. And if I remember correctly,
the problem was the path of the background image.
you could try something like this:

in template:

@page {
background: url( {{ media_root }}/img/watermark.png)
...
}

in view.py:

from django.conf import settings
media_root = settings.MEDIA_ROOT # which is media_root in your
template


Kind regards,

Sebastiaan
Reply all
Reply to author
Forward
0 new messages