Ninjaclasher / dmoj-docker

Docker setup for the DMOJ: Modern Online Judge site.
41 stars 23 forks source link

"View as PDF" function not working #9

Closed thnhub closed 1 year ago

thnhub commented 2 years ago

I have successfully installed the DMOJ website on ubuntu 20.04. However, the "View as PDF" function not working. I see the "View as PDF" button on-page, but it occurs an error when I click on it. This is the error:

"SIGSEGV: invalid_state
corrupt page /problem/aplusb/pdf
site: fatal signal: Segmentation fault
site died (signal 500, exit -11)
panic: go back"

How can I resolve that error, please guide me? Thank you!

powergee commented 2 years ago

That error occurs because DMOJ site is running by root in the docker container. (ChromeDriver cannot be executed by root user.)

You can avoid this problem by adding a line below in function _make of dmoj-docker/dmoj/repo/judge/pdf_problems.py

options.add_argument("--no-sandbox")

However, this solution is not recommended because it is dangerous to run ChromeDriver as root. (ref)

thnhub commented 2 years ago

That error occur because DMOJ site is running by root in the docker container. (ChromeDriver cannot be executed by root user.)

You can avoid this problem by adding a line below in function _make of dmoj-docker/dmoj/repo/judge/pdf_problems.py

options.add_argument("--no-sandbox")

However, this solution is not recommended because it is dangerous to run ChromeDriver as root. (ref)

Thank you very much for your help!

I followed your solution and it worked. I added the command options.add_argument("--no-sandbox") into function _make of SeleniumPDFRender class.

The PDF file was shown on browsers. But there are some other errors, which are: Unicode font and math equation, they do not appear on PDF.

May I ask further, how should I fix those errors?

Thank you!

powergee commented 2 years ago

It is not because of the DMOJ itself, but because there's no font files for your language in docker container(dmoj-base). It can be resolved by simply adding Unicode fonts in dmoj-base.

fonts-noto package includes almost every fonts in the world. You can install it by appending lines below in dmoj-docker/dmoj/base/Dockerfile.

RUN apt-get update && \
    apt-get install -y fonts-noto && \
    fc-cache -f

After adding them, rebuild containers, and start them.

sudo docker-compose down
sudo docker-compose build
sudo docker-compose up -d

Edit: Note that because of the pdfcache, the generated PDF document may not be changed. In this case, modify problem description slightly, and try again.

thnhub commented 2 years ago

OK, thank you @powergee so much! I will try soon.

Ninjaclasher commented 1 year ago

With e6388ecfe4b59614bb4d032653e2b52765cf7ebb, this should no longer be an issue.