PDF generation may not work as expected

Hi All

now i get this error while trying to print PDF

Invalid wkhtmltopdf version

PDF generation may not work as expected.

Please contact your system manager to install correct version.

Correct version : wkhtmltopdf 0.12.x (with patched qt).

could somebody help me as to how i should update the same
Please help
Thanks and Regards

Uploading: 屏幕截图 2024-07-03 165007.png…
Uploading: 屏幕截图 2024-07-03 165148.png…
Uploading: 屏幕截图 2024-07-03 165227.png…

屏幕截图 2024-07-03 165007

image

image

Please help me
Thanks and Regards

try to run this command maybe it work

sudo apt-get install xvfb libfontconfig wkhtmltopdf

I ran this command

You can try:
$ sudo bench install --help

It should show an option to install wkhtmltopdf.
From a hint from Gavin at a “random” place in the forums from some years ago, I found this.
Try to get to the intended result in another way … good luck (searching for the qt patched package on certain websites, which don’t even seem to hold it, etc.).

So that bench install command shown in bench’s --help option when run as superuser is the only one which worked and works for me, resulting in this:

~/frappe/dev-bench$ wkhtmltopdf --version
wkhtmltopdf 0.12.6.1 (with patched qt)

Why is that?
It’s running ansible playbooks integrated in bench. These seem to be the ones which are used by Frappe Cloud and the images it builds for it to run. So this is something the Frappe Uber-Admins give a lot of attention to, so it works well, once the prerequisites are there.
You also can learn many intricacies from these playbooks included in the bench’s code if you read them very attentively.

But you first must uninstall other versions of wkhtmltopdf which might have been installed in another way.
Also, for this to work, and even to show up in the --help, the bench must be run as superuser (e.g. sudo).
I noticed that I even had to install another bench as superuser before that, because the normal bench didn’t run as superuser at all, although I can do any other normal admin task with it.
You also need ansible for this to run, of course. From the environment of the bench, it’s “pip install ansible” or so, maybe you need to run this as sudo, too, I don’t remember exactly.
I didn’t really understand this sudo/non-sudo bench dichotomy for now, any hints are welcome.

Hi bro

I ran the following command and got an error and don’t know how to fix i

fra@fra-virtual-machine:~/frappe-bench$ sudo apt-get --purge remove  wkhtmltopdf
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libdouble-conversion3 libmd4c0 libqt5core5a libqt5dbus5 libqt5gui5 libqt5network5 libqt5positioning5 libqt5printsupport5
  libqt5qml5 libqt5qmlmodels5 libqt5quick5 libqt5sensors5 libqt5svg5 libqt5webchannel5 libqt5webkit5 libqt5widgets5
  libwpe-1.0-1 libwpebackend-fdo-1.0-1 libxcb-xinerama0 libxcb-xinput0 qt5-gtk-platformtheme qttranslations5-l10n
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
  wkhtmltopdf*
0 upgraded, 0 newly installed, 1 to remove and 6 not upgraded.
After this operation, 632 kB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 257311 files and directories currently installed.)
Removing wkhtmltopdf (0.12.6-2) ...
Processing triggers for man-db (2.10.2-1) ...

fra@fra-virtual-machine:~/frappe-bench$ sudo bench install wkhtmltopdf
ansible-playbook 2.10.8
  config file = None
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3/dist-packages/ansible
  executable location = /usr/bin/ansible-playbook
  python version = 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0]
No config file found; using defaults
setting up inventory plugins
host_list declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
script declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
auto declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
yaml declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
ini declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
toml declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'
statically imported: /usr/local/lib/python3.10/dist-packages/bench/playbooks/roles/mariadb/tasks/centos.yml
statically imported: /usr/local/lib/python3.10/dist-packages/bench/playbooks/roles/mariadb/tasks/ubuntu-trusty.yml
statically imported: /usr/local/lib/python3.10/dist-packages/bench/playbooks/roles/mariadb/tasks/ubuntu-xenial_bionic.yml
redirecting (type: modules) ansible.builtin.homebrew to community.general.homebrew
Loading collection community.general from /usr/lib/python3/dist-packages/ansible_collections/community/general
redirecting (type: modules) ansible.builtin.selinux to ansible.posix.selinux
Loading collection ansible.posix from /usr/lib/python3/dist-packages/ansible_collections/ansible/posix
Loading callback plugin default of type stdout, v2.0 from /usr/lib/python3/dist-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.

PLAYBOOK: site.yml ************************************************************************************************************
Positional arguments: site.yml
verbosity: 4
connection: local
timeout: 10
become_method: sudo
tags: ('wkhtmltopdf',)
inventory: ('/etc/ansible/hosts',)
extra_vars: ('{"production": true}',)
forks: 5
2 plays in site.yml

PLAY [localhost] **************************************************************************************************************

TASK [Gathering Facts] ********************************************************************************************************
task path: /usr/local/lib/python3.10/dist-packages/bench/playbooks/site.yml:4
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: root
<127.0.0.1> EXEC /bin/sh -c 'echo ~root && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /root/.ansible/tmp `"&& mkdir "` echo /root/.ansible/tmp/ansible-tmp-1720055433.3975525-9481-73824432277305 `" && echo ansible-tmp-1720055433.3975525-9481-73824432277305="` echo /root/.ansible/tmp/ansible-tmp-1720055433.3975525-9481-73824432277305 `" ) && sleep 0'
Using module file /usr/lib/python3/dist-packages/ansible/modules/setup.py
<127.0.0.1> PUT /root/.ansible/tmp/ansible-local-9478_rkii06c/tmpg6mw34gg TO /root/.ansible/tmp/ansible-tmp-1720055433.3975525-9481-73824432277305/AnsiballZ_setup.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-tmp-1720055433.3975525-9481-73824432277305/ /root/.ansible/tmp/ansible-tmp-1720055433.3975525-9481-73824432277305/AnsiballZ_setup.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python3 /root/.ansible/tmp/ansible-tmp-1720055433.3975525-9481-73824432277305/AnsiballZ_setup.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /root/.ansible/tmp/ansible-tmp-1720055433.3975525-9481-73824432277305/ > /dev/null 2>&1 && sleep 0'
ok: [localhost]
META: ran handlers

TASK [wkhtmltopdf : install base fonts] ***************************************************************************************
task path: /usr/local/lib/python3.10/dist-packages/bench/playbooks/roles/wkhtmltopdf/tasks/main.yml:2
[WARNING]: Skipping plugin (/usr/lib/python3/dist-packages/ansible/plugins/filter/core.py) as it seems to be invalid: cannot
import name 'environmentfilter' from 'jinja2.filters' (/usr/local/lib/python3.10/dist-packages/jinja2/filters.py)
[WARNING]: Skipping plugin (/usr/lib/python3/dist-packages/ansible/plugins/filter/mathstuff.py) as it seems to be invalid:
cannot import name 'environmentfilter' from 'jinja2.filters' (/usr/local/lib/python3.10/dist-packages/jinja2/filters.py)
skipping: [localhost] => {
    "changed": false,
    "skip_reason": "Conditional result was False"
}

TASK [wkhtmltopdf : install base fonts] ***************************************************************************************
task path: /usr/local/lib/python3.10/dist-packages/bench/playbooks/roles/wkhtmltopdf/tasks/main.yml:12
[WARNING]: Skipping plugin (/usr/lib/python3/dist-packages/ansible/plugins/filter/core.py) as it seems to be invalid: cannot
import name 'environmentfilter' from 'jinja2.filters' (/usr/local/lib/python3.10/dist-packages/jinja2/filters.py)
[WARNING]: Skipping plugin (/usr/lib/python3/dist-packages/ansible/plugins/filter/mathstuff.py) as it seems to be invalid:
cannot import name 'environmentfilter' from 'jinja2.filters' (/usr/local/lib/python3.10/dist-packages/jinja2/filters.py)
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: root
<127.0.0.1> EXEC /bin/sh -c 'echo ~root && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /root/.ansible/tmp `"&& mkdir "` echo /root/.ansible/tmp/ansible-tmp-1720055434.085301-9551-78988044835040 `" && echo ansible-tmp-1720055434.085301-9551-78988044835040="` echo /root/.ansible/tmp/ansible-tmp-1720055434.085301-9551-78988044835040 `" ) && sleep 0'
Using module file /usr/lib/python3/dist-packages/ansible/modules/apt.py
<127.0.0.1> PUT /root/.ansible/tmp/ansible-local-9478_rkii06c/tmpv84q25r7 TO /root/.ansible/tmp/ansible-tmp-1720055434.085301-9551-78988044835040/AnsiballZ_apt.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-tmp-1720055434.085301-9551-78988044835040/ /root/.ansible/tmp/ansible-tmp-1720055434.085301-9551-78988044835040/AnsiballZ_apt.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python3 /root/.ansible/tmp/ansible-tmp-1720055434.085301-9551-78988044835040/AnsiballZ_apt.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /root/.ansible/tmp/ansible-tmp-1720055434.085301-9551-78988044835040/ > /dev/null 2>&1 && sleep 0'
fatal: [localhost]: FAILED! => {
    "cache_update_time": 1719972963,
    "cache_updated": false,
    "changed": false,
    "invocation": {
        "module_args": {
            "allow_unauthenticated": false,
            "autoclean": false,
            "autoremove": false,
            "cache_valid_time": 0,
            "deb": null,
            "default_release": null,
            "dpkg_options": "force-confdef,force-confold",
            "force": true,
            "force_apt_get": false,
            "install_recommends": null,
            "only_upgrade": false,
            "package": [
                "libxrender1",
                "libxext6",
                "xfonts-75dpi",
                "xfonts-base"
            ],
            "pkg": [
                "libxrender1",
                "libxext6",
                "xfonts-75dpi",
                "xfonts-base"
            ],
            "policy_rc_d": null,
            "purge": false,
            "state": "present",
            "update_cache": null,
            "update_cache_retries": 5,
            "update_cache_retry_max_delay": 12,
            "upgrade": null
        }
    },
    "msg": "'/usr/bin/apt-get -y -o \"Dpkg::Options::=--force-confdef\" -o \"Dpkg::Options::=--force-confold\"   --force-yes   install 'xfonts-75dpi'' failed: W: --force-yes is deprecated, use one of the options starting with --allow instead.\nE: Failed to fetch https://mirrors.tuna.tsinghua.edu.cn/ubuntu/pool/universe/x/xfonts-75dpi/xfonts-75dpi_1.0.4%2bnmu1.1_all.deb  Temporary failure resolving 'mirrors.tuna.tsinghua.edu.cn'\nE: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?\n",
    "rc": 100,
    "stderr": "W: --force-yes is deprecated, use one of the options starting with --allow instead.\nE: Failed to fetch https://mirrors.tuna.tsinghua.edu.cn/ubuntu/pool/universe/x/xfonts-75dpi/xfonts-75dpi_1.0.4%2bnmu1.1_all.deb  Temporary failure resolving 'mirrors.tuna.tsinghua.edu.cn'\nE: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?\n",
    "stderr_lines": [
        "W: --force-yes is deprecated, use one of the options starting with --allow instead.",
        "E: Failed to fetch https://mirrors.tuna.tsinghua.edu.cn/ubuntu/pool/universe/x/xfonts-75dpi/xfonts-75dpi_1.0.4%2bnmu1.1_all.deb  Temporary failure resolving 'mirrors.tuna.tsinghua.edu.cn'",
        "E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?"
    ],
    "stdout": "Reading package lists...\nBuilding dependency tree...\nReading state information...\nThe following packages were automatically installed and are no longer required:\n  libdouble-conversion3 libmd4c0 libqt5core5a libqt5dbus5 libqt5gui5\n  libqt5network5 libqt5positioning5 libqt5printsupport5 libqt5qml5\n  libqt5qmlmodels5 libqt5quick5 libqt5sensors5 libqt5svg5 libqt5webchannel5\n  libqt5webkit5 libqt5widgets5 libwpe-1.0-1 libwpebackend-fdo-1.0-1\n  libxcb-xinerama0 libxcb-xinput0 qt5-gtk-platformtheme qttranslations5-l10n\nUse 'sudo apt autoremove' to remove them.\nThe following NEW packages will be installed:\n  xfonts-75dpi\n0 upgraded, 1 newly installed, 0 to remove and 6 not upgraded.\nNeed to get 3365 kB of archives.\nAfter this operation, 3778 kB of additional disk space will be used.\nIgn:1 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy/universe amd64 xfonts-75dpi all 1:1.0.4+nmu1.1\nIgn:1 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy/universe amd64 xfonts-75dpi all 1:1.0.4+nmu1.1\nIgn:1 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy/universe amd64 xfonts-75dpi all 1:1.0.4+nmu1.1\nIgn:1 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy/universe amd64 xfonts-75dpi all 1:1.0.4+nmu1.1\nErr:1 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy/universe amd64 xfonts-75dpi all 1:1.0.4+nmu1.1\n  Temporary failure resolving 'mirrors.tuna.tsinghua.edu.cn'\n",
    "stdout_lines": [
        "Reading package lists...",
        "Building dependency tree...",
        "Reading state information...",
        "The following packages were automatically installed and are no longer required:",
        "  libdouble-conversion3 libmd4c0 libqt5core5a libqt5dbus5 libqt5gui5",
        "  libqt5network5 libqt5positioning5 libqt5printsupport5 libqt5qml5",
        "  libqt5qmlmodels5 libqt5quick5 libqt5sensors5 libqt5svg5 libqt5webchannel5",
        "  libqt5webkit5 libqt5widgets5 libwpe-1.0-1 libwpebackend-fdo-1.0-1",
        "  libxcb-xinerama0 libxcb-xinput0 qt5-gtk-platformtheme qttranslations5-l10n",
        "Use 'sudo apt autoremove' to remove them.",
        "The following NEW packages will be installed:",
        "  xfonts-75dpi",
        "0 upgraded, 1 newly installed, 0 to remove and 6 not upgraded.",
        "Need to get 3365 kB of archives.",
        "After this operation, 3778 kB of additional disk space will be used.",
        "Ign:1 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy/universe amd64 xfonts-75dpi all 1:1.0.4+nmu1.1",
        "Ign:1 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy/universe amd64 xfonts-75dpi all 1:1.0.4+nmu1.1",
        "Ign:1 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy/universe amd64 xfonts-75dpi all 1:1.0.4+nmu1.1",
        "Ign:1 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy/universe amd64 xfonts-75dpi all 1:1.0.4+nmu1.1",
        "Err:1 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy/universe amd64 xfonts-75dpi all 1:1.0.4+nmu1.1",
        "  Temporary failure resolving 'mirrors.tuna.tsinghua.edu.cn'"
    ]
}

PLAY RECAP ********************************************************************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=1    skipped=1    rescued=0    ignored=0   

ERROR: Command '['ansible-playbook', '-c', 'local', 'site.yml', '-vvvv', '-e', '{"production": true}', '-t', 'wkhtmltopdf']' returned non-zero exit status 2.


ERROR: Command '['ansible-playbook', '-c', 'local', 'site.yml', '-vvvv', '-e', '{"production": true}', '-t', 'wkhtmltopdf']' returned non-zero exit status 2.
Traceback (most recent call last):
  File "/usr/local/bin/bench", line 8, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python3.10/dist-packages/bench/cli.py", line 132, in cli
    bench_command()
  File "/usr/lib/python3/dist-packages/click/core.py", line 1128, in __call__
    return self.main(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/click/core.py", line 1053, in main
    rv = self.invoke(ctx)
  File "/usr/lib/python3/dist-packages/click/core.py", line 1659, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/lib/python3/dist-packages/click/core.py", line 1659, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/lib/python3/dist-packages/click/core.py", line 1395, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/lib/python3/dist-packages/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/bench/commands/install.py", line 46, in install_wkhtmltopdf
    run_playbook("site.yml", extra_vars=extra_vars, tag="wkhtmltopdf")
  File "/usr/local/lib/python3.10/dist-packages/bench/utils/__init__.py", line 345, in run_playbook
    subprocess.check_call(args, cwd=os.path.join(bench.__path__[0], "playbooks"))
  File "/usr/lib/python3.10/subprocess.py", line 369, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['ansible-playbook', '-c', 'local', 'site.yml', '-vvvv', '-e', '{"production": true}', '-t', 'wkhtmltopdf']' returned non-zero exit status 2.
fra@fra-virtual-machine:~/frappe-bench$

Hi, I was able to fix the problem reported in this post.

I was also struggling with this issue since I was not able to generate PDFs from ERPNext 15, and my install showed wkhtmltopdf version 0.12.6

In order to install the right version with patched qt, I used the following commands on Ubuntu 22.04 using the root user:

• wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6.1-2/wkhtmltox_0.12.6.1-2.jammy_amd64.deb
• sudo apt install -f ./wkhtmltox_0.12.6.1-2.jammy_amd64.deb
• sudo reboot

After rebooting, it successfully showed version: wkhtmltopdf 0.12.6.1 (with patched qt).

However, I still wasn’t able to generate PDFs because of a timeout error, which in my case I fixed by editing the file sites/[site-name]/site_config.json to add “host_name”: “https://127.0.0.1:443” and then after bench restart (on production) there were those nice PDFs showing up again.

Hope this helps someone with same or similar problem.

3 Likes

Hello you can solve this problem use these commands only.

1. sudo apt purge wkhtmltopdf -y

2. wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6.1-2/wkhtmltox_0.12.6.1-2.jammy_amd64.deb

3. sudo dpkg -i wkhtmltox_0.12.5-1.bionic_amd64.deb

4. sudo apt install -f

5. sudo reboot

If you find any issues with the dependencies, install that as well.
Finally check wkhtmltopdf --version
It should be wkhtmltopdf 0.12.5 (with patched qt)

Let’s connect on x (twitter) → x.com
To grow the community frappe

1 Like

@Fei12 please check this link

1 Like

I am also facing the same timeout issue
but it already has a hostname
so what should I do
and site is live (on production) cant change the host name