[App Server] PDF Rendering unavailable

I’m running the open source Anvil Server on Windows 2019 Server. I realize that when you fire up Anvil Server you get the message , “Warning: PDF Rendering not supported on Windows. Renderer not initialised”.

Still, I followed the Anvil Docs and built a Server module and called it from Client code and I got “[ERROR anvil.app-server.run] Error report from client code:
RuntimeUnavailableError: PDF Rendering unavailable”

This makes sense if the Renderer is not initialized per the clear warning provided when the server fires up.

Recognizing that, is there a way to initialize the renderer on Windows (knowing it is unsupported) or is there another technology/architecture to pass the form with contents off somewhere else to be rendered into pdf?

How about setting up a linux environment on your windows server and then running your program in that environment. PDF rendering is available for linux

1 Like

@mesnavunawa great idea, thanks! My application is currently running Anvil Server and Uplink code on Windows. If I set up the Linux environment to handle the PDF rendering task, I would prefer to do this with an Uplink on the Linux environment for just the PDF rendering. Is it possible to have multiple uplinks (1 from Windows and 1 from Linux) for a single Anvil server running a form or do I have to migrate everything over to Linux (i.e. a single Uplink per Server limitation)?

You can have multiple Uplinks. Each Uplink program can establish its own callable functions. Just make sure that the called-function names are distinct, and Anvil will route the function call accordingly.

OUTSTANDING! I will give this a shot and report back success. Thanks for the help.

No dice :frowning:

I stood up a Linux (Ubuntu) environment using WSL on a Windows server. I installed Anvil Server, in that environment and then wrote an uplink script for the PDF Rendering (see below):

import anvil.server
import anvil.pdf
from anvil.pdf import PdfRenderer

anvil.server.connect("<REDACTED>", url="ws://<REDACTED>:3030/_/uplink")

@anvil.server.callable
def create_pdf(name):
  pdf = anvil.pdf.PdfRenderer(scale=0.75, page_size='Letter').render_form(name)
  return pdf

anvil.server.wait_forever()

I ran the uplink script from within the Linux environment and executed the Form from another machine. I can see all the traffic to and from the (other) Windows Server where the original Anvil Server is installed which is running all the communications with the form and the Client code. All good so far. I see the Windows Server call and utilize the create_pdf function on the Linux Server and I see it interact and the result is the following:

[DEBUG anvil.dispatcher.core] Dispatch! anvil.private.pdf.component_to_pdf for Bid_Qualification_Sheet
Calling function 'anvil.private.pdf.component_to_pdf' for app 'Bid_Qualification_Sheet' (ID server-2NEs8VW7aCNQPxq+WHHcKg==)
[DEBUG anvil.dispatcher.core] Dispatch! anvil.private.pdf.do_print for Bid_Qualification_Sheet
Worker terminated for IDs set() (return code None)
[ERROR anvil.app-server.run] Error report from client code:
RuntimeUnavailableError: PDF Rendering unavailable
Traceback:
  /home/dbproptracker/.local/lib/python3.8/site-packages/anvil/_threaded_server.py:393
  /home/dbproptracker/.local/lib/python3.8/site-packages/anvil/server.py:278
  /home/dbproptracker/.local/lib/python3.8/site-packages/anvil/server.py:286
  /home/dbproptracker/.local/lib/python3.8/site-packages/anvil/pdf.py:12
  dbPROPTRACKER_bqs_uplink_script-3DS-LINUX-SERVER.py:10
  app/Bid_Qualification_Sheet/BQS/__init__.py:1390
  app/Bid_Qualification_Sheet/BQS/__init__.py:1148

The “RuntimeUnavailableError: PDF Rendering unavailable” part seems to be coming from the Linux environment (note the /home source of the first 4 lines of the Traceback).

So if I am understanding this correctly, the Uplink on the Linux environment is interacting with the Anvil Server on the Windows environment correctly, but the Linux environment doesn’t have the PDF Rendering capability. I followed these instructions to configure the Linux environment for Chrome & Ghostscript, but I didn’t run it inside a virtual environment as that seemed optional…

Thoughts?

Just to follow up, even when I ran it from within a venv on the Linux environment run within the WSL on Windows Server 2019 (same as above but with the lowest layer being a venv) it still fails telling me PDF Rendering unavailable :frowning:

[DEBUG anvil.dispatcher.core] Dispatch! anvil.private.pdf.component_to_pdf for Bid_Qualification_Sheet
Calling function 'anvil.private.pdf.component_to_pdf' for app 'Bid_Qualification_Sheet' (ID server-HvEIVRRxtQMOXZISaB77/Q==)
[DEBUG anvil.dispatcher.core] Dispatch! anvil.private.pdf.do_print for Bid_Qualification_Sheet
Worker terminated for IDs set() (return code None)
[ERROR anvil.app-server.run] Error report from client code:
RuntimeUnavailableError: PDF Rendering unavailable
Traceback:
  /home/dbproptracker/.local/lib/python3.8/site-packages/anvil/_threaded_server.py:393
  /home/dbproptracker/.local/lib/python3.8/site-packages/anvil/server.py:278
  /home/dbproptracker/.local/lib/python3.8/site-packages/anvil/server.py:286
  /home/dbproptracker/.local/lib/python3.8/site-packages/anvil/pdf.py:12
  /mnt/c/dbPROPTRACKER/Anvil/dbPROPTRACKER_bqs_uplink_script-3DS-LINUX-SERVER.py:10
  app/Bid_Qualification_Sheet/BQS/__init__.py:1390
  app/Bid_Qualification_Sheet/BQS/__init__.py:1148

@irm Did you ever manage to get this working? I’m also looking for a way to handle pdf rendering on Windows and WSL occurred to me as a potential solution.

Hi Owen,

No I didn’t. I even went as far as to stand up a LINUX box and then try to get it running in there via a parallel Uplink Script, but it failed on LINUX as well. Interestingly, yesterday the Anvil team put out an E-Mail that included something I was going to try in the next few days (https://anvil.works/learn/tutorials/pdfs?utm_medium=email&utm_source=newsletter-20-11). I’ll let you know if it works for me.

1 Like

I’ve managed to get that example app running on WSL2 with Ubuntu 20.04

We are still struggling with this. There seems to be a difference in behavior between the environment available via anvil.works and what is in the open source downloadable anvil-app-server via GitHub. Are there known differences in the PDF module which are yet to be upgraded in the open source code?

Hi let me know, if you’ve found any appropriate solution for that? Because I am facing the same issue with my app hosted on ec2 linux instance

You are unlikely to get an answer to an old post.

Please ask a new question.