0

My application is written in Flask. The app in Flask runs at mysite.pythonanywhere.com I use python and the pdfkit library to convert the html template to pdf format.

In my development environment I use the version wkhtmltopdf 0.12.6 (with patched qt). When executing the conversion from html to pdf format in the development environment, I get the number of pages and pages correctly displayed in the converted pdf file.

Attached is a screenshot of the section of the document in pdf format that shows 1 of 1 (indicating that it is on page 1 of 1)

enter image description here

When executing the same report and conversion from html to pdf format in the app running at mysite.pythonanywhere.com the page number is not displayed.

Attached is the screenshot of the section of the report where the page number is supposed to be displayed:

enter image description here

As you can see, the page number is not displayed in the file with pdf format that was generated by pdfkit during the conversion from html to pdf format.

After having investigated the possible cause of this behavior when the app is running on the mysite.pythonanywhere.com, I found that the following message is displayed in the mysite.pythonanywhere.com.server.log log file:

2021-07-01 20:26:16 The switch --footer-right, is not support using unpatched qt, and will be ignored.

Investigating the cause of the previously indicated message. I found that the reason for this message is that the version of wkhtmltopdf that I run in the development environment is a version that has the patch qt, and the version of wkhtmltopdf that I run in mysite.pythonanywhere.com is a version that does not have the patch qt.

When executing the command:

$ wkhtmltopdf --version

in development environment, I get version

wkhtmltopdf 0.12.6 (with patched qt)

When executing the command:

$ wkhtmltopdf --version

in production environment, I get version

wkhtmltopdf 0.12.2.4

enter image description here

According to the documentation found on the message displayed on the mysite.pythonanywhere.com server, the message is related to the fact that the version that is running on the server is a version that does not have the qt patch and that is the cause that the number page are not displayed in the pdf file generated by pdfkit

A possible solution found on stackoverflow suggests that it is necessary to install an updated version of wkhtmltopdf, that is, a version that has the qt patch. Error when trying to display the number of pages in PdfKit

The question is: How to update wkhtmltopdf version in pythonanywhere.com virtual environment?

Thank you very much for any guidance you can give.

Ramiro
  • 369
  • 3
  • 14

1 Answers1

1

You cannot update the qt version on PythonAnywhere. Particularly since it appears that the feature that you want requires some sort of patched version of it.

Glenn
  • 7,262
  • 1
  • 17
  • 23
  • My apologies if I have not explained myself clearly. The situation does not point to update the version of qt. The solution is to install an updated version of the wkhtmltopdf package that includes the qt patch. The wkhtmltopdf package installation process is basic and not complicated. The detail is that I do not have the necessary privileges to perform the installation. – Ramiro Jul 03 '21 at 01:15
  • The release that is installed in the mysite.pythonanywhere.com environment is version = "16.04.6 LTS (Xelenial Xerus)" and the architecture is "amd64". – Ramiro Jul 03 '21 at 01:19
  • Reviewing the stable series of wkhtmltopdf on the page https://wkhtmltopdf.org/downloads.html it is necessary to download the current stable series is 0.12.6, which was released on June 11, 2020 – Ramiro Jul 03 '21 at 01:30
  • Specifically it is the stable series for the OS / Distribution: Ubuntu; Supported on: 16.04 (Xenial); Architecture: amd64 – Ramiro Jul 03 '21 at 01:32
  • Which is located at https: //github.com/wkhtmltopdf/packaging/download/0.12.6-1/wkhtmltox_0.12.6-1.xenial_amd64.deb – Ramiro Jul 03 '21 at 01:34
  • The following link to stackoverflow includes instructions for installing wkhtmltopdf with qt patched version: https://stackoverflow.com/questions/34479040/how-to-install-wkhtmltopdf-with-patched-qt/34521838 – Ramiro Jul 03 '21 at 01:39
  • The message "The switch --footer-right, is not support using unpatched qt, and will be ignored" is associated with the instruction in python code: options = { 'page-size': 'Letter', 'encoding': "UTF-8", 'footer-right': '[page] of [topage]', } – Ramiro Jul 03 '21 at 01:44
  • That is to say at the moment it has running in mysite.pythonanywhere.com wkhtmltopdf 0.12.2.4 that does not recognize the option 'footer-right': '[page] of [topage]' sent to pdkfit; if an updated version of wkhtmltopdf with qt patch is installed the option 'footer-right': '[page] of [topage]' will be accepted by wkhtmltopdf at the time of conversion from html to pdf format. Which solves the incompatibility of the wkhtmltopdf version to display the page numbers in the generated pdf document. – Ramiro Jul 03 '21 at 01:55
  • I hope this clarification brings clarity on the requirement to pythonanywhere to install an updated version of wkhtmltopdf on the pythonanywhere.com server. – Ramiro Jul 03 '21 at 02:00
  • Don't know if that'd solve your issue, but on newer system image ('glastonbury') you'd get Ubuntu 20.04.2 LTS and wkhtmltopdf 0.12.5. – caseneuve Jul 03 '21 at 12:39
  • @caseneuve (To: caseneuve) - Could you please run the following command from the bash console of the 'glastonbury' system? wkhtmltopdf --version You should get a response similar to this: wkhtmltopdf 0.12.5 (with patched qt) If you get the message "with patched qt" then it works for me. Thanks! – Ramiro Jul 04 '21 at 06:30
  • @Ramiro - yes, I run that command already and showed you the output above (it's without the patch). – caseneuve Jul 04 '21 at 09:03
  • @caseneuve (To: caseneuve) - if that's the case. What are your chances to install wkhtmltopdf version 0.12.6 (@'glastonbury')- please note that wkhtmltopdf version 0.12.6 has the (patched qt) – Ramiro Jul 04 '21 at 10:35
  • Once a system image is deployed, the packages installed are fixed -- you need to wait for another system image which will come with updated packages. – caseneuve Jul 04 '21 at 17:33