[IMP]: Updated report fix related to wkhtmltopdf

This commit is contained in:
Bhumika Trivedi 2018-11-30 14:04:35 +05:30
parent d4382431bd
commit efa255c886
2 changed files with 14 additions and 6 deletions

View File

@ -76,7 +76,7 @@ PostgreSQL server :
In order to print PDF reports, you must install wkhtmltopdf_ yourself: In order to print PDF reports, you must install wkhtmltopdf_ yourself:
the version of wkhtmltopdf_ available in debian repositories does not support the version of wkhtmltopdf_ available in debian repositories does not support
headers and footers so it can not be installed automatically. headers and footers so it can not be installed automatically.
The recommended version is 0.12.1 and is available on `the wkhtmltopdf download page`_, The recommended version is 0.12.5 and is available on `the wkhtmltopdf download page`_,
in the archive section. in the archive section.
Repository Repository
@ -513,7 +513,7 @@ offcial Flectra `docker image <https://hub.docker.com/r/flectrahq/flectra/>`_ pa
http://www.enterprisedb.com/products-services-training/pgdownload http://www.enterprisedb.com/products-services-training/pgdownload
.. _Quilt: http://en.wikipedia.org/wiki/Quilt_(software) .. _Quilt: http://en.wikipedia.org/wiki/Quilt_(software)
.. _saas: https://www.flectrahq.com .. _saas: https://www.flectrahq.com
.. _the wkhtmltopdf download page: https://github.com/wkhtmltopdf/wkhtmltopdf/releases/tag/0.12.1 .. _the wkhtmltopdf download page: https://github.com/wkhtmltopdf/wkhtmltopdf/releases/tag/0.12.5
.. _UAC: http://en.wikipedia.org/wiki/User_Account_Control .. _UAC: http://en.wikipedia.org/wiki/User_Account_Control
.. _wkhtmltopdf: http://wkhtmltopdf.org .. _wkhtmltopdf: http://wkhtmltopdf.org
.. _pip: https://pip.pypa.io .. _pip: https://pip.pypa.io

View File

@ -44,6 +44,7 @@ def _get_wkhtmltopdf_bin():
# Check the presence of Wkhtmltopdf and return its version at Flectra start-up # Check the presence of Wkhtmltopdf and return its version at Flectra start-up
wkhtmltopdf_state = 'install' wkhtmltopdf_state = 'install'
wkhtmltopdf_dpi_zoom_ratio = False
try: try:
process = subprocess.Popen( process = subprocess.Popen(
[_get_wkhtmltopdf_bin(), '--version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE [_get_wkhtmltopdf_bin(), '--version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE
@ -61,6 +62,8 @@ else:
wkhtmltopdf_state = 'upgrade' wkhtmltopdf_state = 'upgrade'
else: else:
wkhtmltopdf_state = 'ok' wkhtmltopdf_state = 'ok'
if LooseVersion(version) >= LooseVersion('0.12.2'):
wkhtmltopdf_dpi_zoom_ratio = True
if config['workers'] == 1: if config['workers'] == 1:
_logger.info('You need to start Flectra with at least two workers to print a pdf version of the reports.') _logger.info('You need to start Flectra with at least two workers to print a pdf version of the reports.')
@ -206,7 +209,7 @@ class IrActionsReport(models.Model):
:param set_viewport_size: Enable a viewport sized '1024x1280' or '1280x1024' depending of landscape arg. :param set_viewport_size: Enable a viewport sized '1024x1280' or '1280x1024' depending of landscape arg.
:return: A list of string representing the wkhtmltopdf process command args. :return: A list of string representing the wkhtmltopdf process command args.
''' '''
command_args = [] command_args = ['--disable-local-file-access']
if set_viewport_size: if set_viewport_size:
command_args.extend(['--viewport-size', landscape and '1024x1280' or '1280x1024']) command_args.extend(['--viewport-size', landscape and '1024x1280' or '1280x1024'])
@ -234,14 +237,19 @@ class IrActionsReport(models.Model):
else: else:
command_args.extend(['--margin-top', str(paperformat_id.margin_top)]) command_args.extend(['--margin-top', str(paperformat_id.margin_top)])
dpi = None
if specific_paperformat_args and specific_paperformat_args.get('data-report-dpi'): 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_id.dpi: elif paperformat_id.dpi:
if os.name == 'nt' and int(paperformat_id.dpi) <= 95: if os.name == 'nt' and int(paperformat_id.dpi) <= 95:
_logger.info("Generating PDF on Windows platform require DPI >= 96. Using 96 instead.") _logger.info("Generating PDF on Windows platform require DPI >= 96. Using 96 instead.")
command_args.extend(['--dpi', '96']) dpi = 96
else: else:
command_args.extend(['--dpi', str(paperformat_id.dpi)]) dpi = paperformat_id.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'): 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'])]) command_args.extend(['--header-spacing', str(specific_paperformat_args['data-report-header-spacing'])])