[FIX] Fix Watermark from PNG

pull/144/head
etobella 2017-06-20 11:23:36 +02:00
parent 5df8064fc0
commit 6dacecae08
3 changed files with 17 additions and 1 deletions

View File

@ -3,9 +3,17 @@ cache: pip
addons:
apt:
sources:
- pov-wkhtmltopdf
packages:
- expect-dev # provides unbuffer utility
- python-lxml # because pip installation is slow
- wkhtmltopdf # only add if needed and check the before_install section below
# set up an X server to run wkhtmltopdf.
before_install:
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"
language: python

View File

@ -4,7 +4,8 @@
{
"name": "Pdf watermark",
"version": "10.0.1.0.0",
"author": "Therp BV,Odoo Community Association (OCA)",
"author": "Therp BV, "
"Odoo Community Association (OCA)",
"license": "AGPL-3",
"category": "Reporting",
"summary": "Add watermarks to your QWEB PDF reports",

View File

@ -8,6 +8,12 @@ from pyPdf.utils import PdfReadError
from PIL import Image
from StringIO import StringIO
from odoo import api, models, tools
from PIL import PdfImagePlugin # flake8: noqa
# PdfImagePlugin must be loaded in order to work PNG to PDF transformation
# This issue is related to Pillow creation, as can be seen in its source code:
# https://github.com/python-pillow/Pillow/blob/master/PIL/PdfImagePlugin.py
logger = getLogger(__name__)
@ -40,6 +46,7 @@ class Report(models.Model):
except PdfReadError:
# let's see if we can convert this with pillow
try:
Image.init()
image = Image.open(StringIO(watermark))
pdf_buffer = StringIO()
if image.mode != 'RGB':