Skip to content

Commit

Permalink
[FIX] report: support for wkhtmltopdf 0.12.5
Browse files Browse the repository at this point in the history
This revision brings the compatibility for our reports
using wkhtmltopdf 0.12.5.

Up to now,
the supported wkhtmltopdf version was 0.12.1.

The goal of this revision is to add the compatibility
to wkhtmltopdf 0.12.5,
while keeping the same exact rendering than in 0.12.1.

There is a behavior change with the `--dpi` parameter,
which no longer has a "zoom" level effect as it did with 0.12.1.

To deal with it, we pass the `--zoom` parameter when
the detected version installed of wkhtmltopdf is after 0.12.2,
with a ratio 96:dpi. 96 being the default dpi of wkhtmltopdf.

This trick allows to render the reports with the exact same
zoom level, whatever the dpi value configured in the reports paperformat.
(at least with dpi values up to 149, after 150, included,
the dpi parameter with wkhtmltopdf 0.12.1 as a weird behavior,
it no longer zoom out)

opw-1907346
  • Loading branch information
beledouxdenis committed Nov 21, 2018
1 parent 258eaa7 commit 9480dce
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions addons/report/models/report.py
Expand Up @@ -50,6 +50,7 @@ def _get_wkhtmltopdf_bin():
# Check the presence of Wkhtmltopdf and return its version at Odoo start-up
#--------------------------------------------------------------------------
wkhtmltopdf_state = 'install'
wkhtmltopdf_dpi_zoom_ratio = False
try:
process = subprocess.Popen(
[_get_wkhtmltopdf_bin(), '--version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE
Expand All @@ -67,6 +68,8 @@ def _get_wkhtmltopdf_bin():
wkhtmltopdf_state = 'upgrade'
else:
wkhtmltopdf_state = 'ok'
if LooseVersion(version) >= LooseVersion('0.12.2'):
wkhtmltopdf_dpi_zoom_ratio = True

if config['workers'] == 1:
_logger.info('You need to start Odoo with at least two workers to print a pdf version of the reports.')
Expand Down Expand Up @@ -524,14 +527,19 @@ def _build_wkhtmltopdf_args(self, paperformat, specific_paperformat_args=None):
else:
command_args.extend(['--margin-top', str(paperformat.margin_top)])

dpi = None
if specific_paperformat_args and specific_paperformat_args.get('data-report-dpi'):
command_args.extend(['--dpi', str(specific_paperformat_args['data-report-dpi'])])
dpi = int(specific_paperformat_args['data-report-dpi'])
elif paperformat.dpi:
if os.name == 'nt' and int(paperformat.dpi) <= 95:
_logger.info("Generating PDF on Windows platform require DPI >= 96. Using 96 instead.")
command_args.extend(['--dpi', '96'])
dpi = 96
else:
command_args.extend(['--dpi', str(paperformat.dpi)])
dpi = paperformat.dpi
if dpi:
command_args.extend(['--dpi', str(dpi)])
if wkhtmltopdf_dpi_zoom_ratio:
command_args.extend(['--zoom', str(96.0 / dpi)])

if specific_paperformat_args and specific_paperformat_args.get('data-report-header-spacing'):
command_args.extend(['--header-spacing', str(specific_paperformat_args['data-report-header-spacing'])])
Expand Down

0 comments on commit 9480dce

Please sign in to comment.