[V11] PDF Print BUG - Zoomed IN on PDF View

Hello I updated my Test server and other client server to the latest V11 build and this is a new issue I have noticed.

My Server is on
ERPNext: v11.1.67 (version-11)
Frappe Framework: v11.1.61 (version-11)

Print View shows correct, Print button works fine but only when PDF it is zoomed in.

Here is the Screenshots:
Print View

PDF View - Everything is Zoomed including the Letterhead in other clients PDF View.

This is a standard print format and there is no customisation done. Also the screenshot is from test server which does not have any customisation in terms of print as well as forms.

Anyone else updated to the latest V11 build and facing similar issue?

1 Like

Hi @fkardame,

we have seen a similar issue, tough different. If you use a recent version of wkhtmltopdf (we use 0.12.5 rather than 0.12.3 which ships with ERPNext), it has a new feature smart-shrinking. This will “optimise” the use of the space. In some cases it shrinks, but might also zoom.

There are different ways to go about disabling this. If you can fork/branch, simply add the “disable-smart-shrinking”: None option to pdf.py. This works like a charm. If not, you might want to rewrite the wkhtmltopdf bash script to add the command-line parameter, something like

$ sudo mv /usr/local/bin/wkhtmltopdf /usr/local/bin/wkhtmltopdf_original
$ sudo nano /usr/local/bin/wkhtmltopdf
#!/bin/bash
/usr/local/bin/wkhtmltopdf_original --disable-smart-shrinking $@

Hope this helps.

2 Likes

I am getting error when following you steps.

Traceback (most recent call last):
  File "/home/erpnext/frappe-bench/env/src/pdfkit/pdfkit/configuration.py", line 21, in __init__
    with open(self.wkhtmltopdf) as f:
FileNotFoundError: [Errno 2] No such file or directory: b''

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/utils/pdf.py", line 24, in get_pdf
    pdfkit.from_string(html, fname, options=options or {})
  File "/home/erpnext/frappe-bench/env/src/pdfkit/pdfkit/api.py", line 66, in from_string
    configuration=configuration)
  File "/home/erpnext/frappe-bench/env/src/pdfkit/pdfkit/pdfkit.py", line 38, in __init__
    self.configuration = (Configuration() if configuration is None
  File "/home/erpnext/frappe-bench/env/src/pdfkit/pdfkit/configuration.py", line 27, in __init__
    'https://github.com/JazzCore/python-pdfkit/wiki/Installing-wkhtmltopdf' % self.wkhtmltopdf)
OSError: No wkhtmltopdf executable found: "b''"
If this file exists please check that this process can read it. Otherwise please install wkhtmltopdf - https://github.com/JazzCore/python-pdfkit/wiki/Installing-wkhtmltopdf

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/app.py", line 66, in application
    response = frappe.api.handle()
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/api.py", line 56, in handle
    return frappe.handler.handle()
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/handler.py", line 21, in handle
    data = execute_cmd(cmd)
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/handler.py", line 56, in execute_cmd
    return frappe.call(method, **frappe.form_dict)
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/__init__.py", line 1036, in call
    return fn(*args, **newargs)
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/utils/print_format.py", line 92, in download_pdf
    frappe.local.response.filecontent = get_pdf(html)
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/utils/pdf.py", line 32, in get_pdf
    if ("ContentNotFoundError" in e.message
AttributeError: 'OSError' object has no attribute 'message'

Once I move the original file it works but again zoomed in

There is an easy test if the hack has worked, try

$ wkhtmltopdf https://www.google.com google.pdf

If this does not work, I guess the bash script is not in place (and it has to be named exactly like this to override the behaviour)…

I checked the file location.

This is the bash file.
Screenshot_20191028_122448

This is the location.
Screenshot_20191028_122510

That looks almost good, the execution flag (x) is missing on wkhtmltopdf.

Use

$ sudo chmod 755 wkhtmltopdf

Then, try

$ wkhtmltopdf https://www.google.com google.pdf
1 Like

Works but still zoomed.

Sorry, then this was not it… but I guess other people using the default print format should observe the same thing…? Have you considered using a custom print format?

Yes We use custom print format for everything but for debugging we go back to standard to make sure we are not making any mistake in the custom pf.

I think I read the same issue in one of the wkhtmltopdf issue list. I will do some more search on this.

My current version is:
wkhtmltopdf -V
wkhtmltopdf 0.12.3 (with patched qt)

Update:
It looks like frappe team have moved to wkhtmltopdf 0.12.5

@lasalesi how can I upgrade wkhtml either directly with apt or any other way ?

Ah, I see; I think in productive use in any case, custom print is the way to go to achieve a professional output.

You can update using (assuming you have a Debian or related distro):

$ wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.5/wkhtmltox_0.12.5-1.stretch_amd64.deb
$ sudo dpkg --install wkhtmltox_0.12.5-1.stretch_amd64.deb
$ wkhtmltopdf -V

multiple dependency errors.

Can you share your distro/version, and the dependencies?

Ubuntu 18.04
Error log:

dpkg: dependency problems prevent configuration of wkhtmltox:
 wkhtmltox depends on libjpeg62-turbo; however:
  Package libjpeg62-turbo is not installed.

dpkg: error processing package wkhtmltox (--install):
 dependency problems - leaving unconfigured
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Errors were encountered while processing:
 wkhtmltox

If I try to install libjpeg64-turbo then it have another dependency which cannot be replaced.

Try

$ sudo apt-get -f install

this should resolve dependencies…

No it force doesn’t always help when the dependencies are already present with its own conflict.

sudo apt-get -f install libjpeg62-dev
Reading package lists... Done
Building dependency tree       
Reading state information... Done
You might want to run 'apt --fix-broken install' to correct these.
The following packages have unmet dependencies:
 libjpeg-turbo8-dev : Conflicts: libjpeg62-dev but 1:6b2-3 is to be installed
 libjpeg62-dev : Depends: libjpeg62 (= 1:6b2-3) but it is not going to be installed
 wkhtmltox : Depends: libjpeg62-turbo but it is not installable
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).

Without the package -f install will fix rather than force (alternatively use --fix-broken install, is the same). You’ll have to resolve the conflicts in any case, sorry.

Can anyone else try to update to latest v11 release and check if they have the same issue of pdf zoomed in ?

It is confirmed that everyone who will update to latest V11 release with by affected by this pdf issue.
As I asked my dev team to update their local server and they have the same issue now.

Just found out that this issue already has a fix in version-11-hotfix.

fix: disable smart shrinking for version 0.12.5 by rohitwaghchaure · Pull Request #8675 · frappe/frappe · GitHub.

So hopefully will get resolved in the next version-11 release.

1 Like

@rohit_w

fix: disable smart shrinking for version 0.12.5 by rohitwaghchaure · Pull Request #8675 · frappe/frappe · GitHub.

This hotfix didnt fix all the deployment, tried it on test/development server it fixed the issue but doesnt seem to fix it on production, while there is no changes done in production .

All are on same version of wkhtmltopdf

wkhtmltopdf 0.12.3 (with patched qt)