From 6dacecae08baf881a3e0c7f9cd665e464fe41ddf Mon Sep 17 00:00:00 2001 From: etobella Date: Tue, 20 Jun 2017 11:23:36 +0200 Subject: [PATCH 1/2] [FIX] Fix Watermark from PNG --- .travis.yml | 8 ++++++++ report_qweb_pdf_watermark/__manifest__.py | 3 ++- report_qweb_pdf_watermark/models/report.py | 7 +++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index fd7bbfc6..5337bc3f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/report_qweb_pdf_watermark/__manifest__.py b/report_qweb_pdf_watermark/__manifest__.py index e6e779d4..95b4c536 100644 --- a/report_qweb_pdf_watermark/__manifest__.py +++ b/report_qweb_pdf_watermark/__manifest__.py @@ -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", diff --git a/report_qweb_pdf_watermark/models/report.py b/report_qweb_pdf_watermark/models/report.py index 5125cd3c..82d0d311 100644 --- a/report_qweb_pdf_watermark/models/report.py +++ b/report_qweb_pdf_watermark/models/report.py @@ -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': From 7d621022b00b473b734f1e0d7cb19727012be8af Mon Sep 17 00:00:00 2001 From: etobella Date: Wed, 21 Jun 2017 10:36:37 +0200 Subject: [PATCH 2/2] [FIX] Change travis configuration to download wkhtmltopdf last version --- .travis.yml | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5337bc3f..5beaf65f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,17 +3,9 @@ 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 @@ -37,6 +29,7 @@ virtualenv: install: - git clone --depth=1 https://github.com/OCA/maintainer-quality-tools.git ${HOME}/maintainer-quality-tools - export PATH=${HOME}/maintainer-quality-tools/travis:${PATH} + - export WKHTMLTOPDF_VERSION=0.12.4 - travis_install_nightly script: