[FIX] report: support for wkhtmltopdf 0.12.5

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

closes odoo/odoo#28864
This commit is contained in:
Denis Ledoux
2018-11-21 09:30:02 +00:00
parent 1f8788deef
commit af476c6949
+11 -3
View File
@@ -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
@@ -67,6 +68,8 @@ else:
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.')
@@ -524,14 +527,19 @@ class Report(models.Model):
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'])])