Browse Source

Merge pull request #144 from etobella/10.0-fix_watermark_png

[FIX] Fix Watermark from PNG
pull/146/head
Pedro M. Baeza 8 years ago
committed by GitHub
parent
commit
074f3a2be5
  1. 1
      .travis.yml
  2. 3
      report_qweb_pdf_watermark/__manifest__.py
  3. 7
      report_qweb_pdf_watermark/models/report.py

1
.travis.yml

@ -29,6 +29,7 @@ virtualenv:
install: install:
- git clone --depth=1 https://github.com/OCA/maintainer-quality-tools.git ${HOME}/maintainer-quality-tools - 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 PATH=${HOME}/maintainer-quality-tools/travis:${PATH}
- export WKHTMLTOPDF_VERSION=0.12.4
- travis_install_nightly - travis_install_nightly
script: script:

3
report_qweb_pdf_watermark/__manifest__.py

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

7
report_qweb_pdf_watermark/models/report.py

@ -8,6 +8,12 @@ from pyPdf.utils import PdfReadError
from PIL import Image from PIL import Image
from StringIO import StringIO from StringIO import StringIO
from odoo import api, models, tools 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__) logger = getLogger(__name__)
@ -40,6 +46,7 @@ class Report(models.Model):
except PdfReadError: except PdfReadError:
# let's see if we can convert this with pillow # let's see if we can convert this with pillow
try: try:
Image.init()
image = Image.open(StringIO(watermark)) image = Image.open(StringIO(watermark))
pdf_buffer = StringIO() pdf_buffer = StringIO()
if image.mode != 'RGB': if image.mode != 'RGB':

Loading…
Cancel
Save