blank pages on grade report file pdf on latest 4.1.9+ (Build: 20240315) $version = 2022112809.07

blank pages on grade report file pdf on latest 4.1.9+ (Build: 20240315) $version = 2022112809.07

by Lewi S. Kristianto (visiniaga) -
Number of replies: 11

Environment:

php version 7.4.3-4ubuntu2.20 
Ubuntu 20.04.6 LTS 

We get some problem grade report with jpg file on the version 

moodle 4.1.9+ (Build: 20240315)
$version  = 2022112809.00;
$release  = '4.1.9+ (Build: 20240315)';

from files moodle/mod/assign/feedback/editpdf/version.php

$plugin->version   = 2022112801;
$plugin->requires  = 2022111800;
$plugin->component = 'assignfeedback_editpdf';

it show same version with moodle 4.1.9, that have 

$version  = 2022112809.00; 
$release  = '4.1.9 (Build: 20240212)';

from files moodle/mod/assign/feedback/editpdf/version.php

$plugin->version   = 2022112801;
$plugin->requires  = 2022111800;
$plugin->component = 'assignfeedback_editpdf';

while checking with moodle 4.1.9 this problem not occurring,
as we have already upgraded the database to 4.1.9+, 
while downgrading cannot be done, doing workaround for copying all folder feedback on path

moodle/mod/assign/feedback folder from 4.1.9 to 4.1.9+ 

but this may cause any compatible issue, any fix for the current build 4.1.9+ ?
what is the difference for the both version for the assignfeedback_editpdf?



Notes:
It shows different result, error log nginx:

2024/03/18 14:37:01 [error] 788#788: *3974868 FastCGI sent in stderr: "PHP message: Default exception handler: Error generating image with ghostscript, debugging info: <pre>Command:
'/usr/bin/gs.sh' -q -sDEVICE=png16m -dSAFER -dBATCH -dNOPAUSE -r'100' -dFirstPage='1' -dLastPage='1' -dDOINTERPOLATE -dGraphicsAlphaBits=4 -dTextAlphaBits=4 -sOutputFile='/tmp/requestdir/hQjE/65f7ef1d38ab0/65f7ef1d5254a/image_page0.png' '/tmp/requestdir/hQjE/65f7ef1d38ab0/65f7ef1d5254a/error.pdf'
Result:
Output:
</pre> Debug:
Error code: errorgenerateimage
* line 593 of /mod/assign/feedback/editpdf/classes/pdf.php: moodle_exception thrown
* line 783 of /mod/assign/feedback/editpdf/classes/pdf.php: call to assignfeedback_editpdf\pdf->get_image()
* line 555 of /mod/assign/feedback/editpdf/classes/pdf.php: call to assignfeedback_editpdf\pdf::get_error_image()
* line 441 of /mod/assign/feedback/editpdf/classes/document_services.php: call to assignfeedback_editpdf\pdf->get_images()
* line 603 of /mod/assign/feedback/editpdf/classes/document_services.php: call to assignfeedback_editpdf\docu" while reading response header from upstream, client: 117.102.226.70, server: hostname-petralms, request: "GET /mod/assign/feedback/editpdf/ajax.php?sesskey=ycX0xGdEIc&action=pollconversions&userid=12609&attemptnumber=0&assignmentid=15043&readonly=0 HTTP/2.0", upstream: "fastcgi://unix:/var/run/php/php7.4-fpm-moodle.sock:", host: "hostname-petralms", referrer: "https://hostname-petralms/mod/assign/view.php?id=96456&action=grader&userid=12609"
2024/03/18 14:37:13 [error] 788#788: *3974868 FastCGI sent in stderr: "PHP message: Default exception handler: Error generating image with ghostscript, debugging info: <pre>Command:
'/usr/bin/gs.sh' -q -sDEVICE=png16m -dSAFER -dBATCH -dNOPAUSE -r'100' -dFirstPage='1' -dLastPage='1' -dDOINTERPOLATE -dGraphicsAlphaBits=4 -dTextAlphaBits=4 -sOutputFile='/tmp/requestdir/hQjE/65f7ef29205f3/65f7ef293a25b/image_page0.png' '/tmp/requestdir/hQjE/65f7ef29205f3/65f7ef293a25b/error.pdf'
Result:


Output:
</pre> Debug:
Error code: errorgenerateimage
* line 593 of /mod/assign/feedback/editpdf/classes/pdf.php: moodle_exception thrown
* line 783 of /mod/assign/feedback/editpdf/classes/pdf.php: call to assignfeedback_editpdf\pdf->get_image()
* line 555 of /mod/assign/feedback/editpdf/classes/pdf.php: call to assignfeedback_editpdf\pdf::get_error_image()
* line 441 of /mod/assign/feedback/editpdf/classes/document_services.php: call to assignfeedback_editpdf\pdf->get_images()
* line 603 of /mod/assign/feedback/editpdf/classes/document_services.php: call to assignfeedback_editpdf\docu" while reading response header from upstream, client: 117.102.226.70, server: hostname-petralms, request: "GET /mod/assign/feedback/editpdf/ajax.php?sesskey=ycX0xGdEIc&action=pollconversions&userid=12609&attemptnumber=0&assignmentid=15043&readonly=0 HTTP/2.0", upstream: "fastcgi://unix:/var/run/php/php7.4-fpm-moodle.sock:", host: "hostname-petralms", referrer: "https://hostname-petralms/mod/assign/view.php?id=96456&action=grader&userid=12609"
2024/03/18 14:37:24 [error] 788#788: *3974868 FastCGI sent in stderr: "PHP message: Default exception handler: Error generating image with ghostscript, debugging info: <pre>Command:
'/usr/bin/gs.sh' -q -sDEVICE=png16m -dSAFER -dBATCH -dNOPAUSE -r'100' -dFirstPage='1' -dLastPage='1' -dDOINTERPOLATE -dGraphicsAlphaBits=4 -dTextAlphaBits=4 -sOutputFile='/tmp/requestdir/hQjE/65f7ef3439bef/65f7ef3452f29/image_page0.png' '/tmp/requestdir/hQjE/65f7ef3439bef/65f7ef3452f29/error.pdf'
Attachment Screenshot 2024-03-18 21.35.08.png
Average of ratings: -
In reply to Lewi S. Kristianto (visiniaga)

Re: blank pages on grade report file pdf on latest 4.1.9+ (Build: 20240315) $version = 2022112809.07

by Ken Task -
Picture of Particularly helpful Moodlers
In the debug ....
https://hostname-petralms/mod/assign/blah

hostname-petralms isn't a valid domain name.
Unless you obscured that.

while reading response header from upstream, client: IPADDRESS,
server: hostname-petralms

Does your server know it's FQDN?

What do you have in /etc/hosts

'SoS', Ken

In reply to Ken Task

Re: blank pages on grade report file pdf on latest 4.1.9+ (Build: 20240315) $version = 2022112809.07

by Lewi S. Kristianto (visiniaga) -
Yes, pls ignore about hostname 
In reply to Lewi S. Kristianto (visiniaga)

Re: blank pages on grade report file pdf on latest 4.1.9+ (Build: 20240315) $version = 2022112809.07

by Ken Task -
Picture of Particularly helpful Moodlers
Ok, that was #1 .. now for #2

In your debug,  /usr/bin/gs.sh ... looks strange.

In
Plugins
Activity modules
Assignment
Feedback plugins
Annotate PDF

There is a Path to ghostscript
And a link to Test ghostscript path

Try the Test link.

In
Server
System paths

What do you see for Path to ghostscript.

typically, on linux server, that's in '/usr/bin/' and is 'gs'.
So path would be '/usr/bin/gs' - without the ticks.

'SoS', Ken


In reply to Ken Task

Re: blank pages on grade report file pdf on latest 4.1.9+ (Build: 20240315) $version = 2022112809.07

by Lewi S. Kristianto (visiniaga) -
gs.sh

#!/bin/sh
TIMEOUT=20
export TEMP=/tmp
LOGFILE=/tmp/gs-moodle.log
#/usr/bin/nice -n19 /usr/bin/timeout $TIMEOUT /usr/bin/gs $@
/usr/bin/nice -n19 /usr/bin/gs $@
returncode=$?
if [ "$returncode" -eq 124 ]; then
    echo "$(date -Iseconds) - GS command timed out: /usr/bin/gs $@" >> $LOGFILE
fi
exit $returncode
In reply to Lewi S. Kristianto (visiniaga)

Re: blank pages on grade report file pdf on latest 4.1.9+ (Build: 20240315) $version = 2022112809.07

by Ken Task -
Picture of Particularly helpful Moodlers
So gs.sh is a shell script of your own making.

https://manpages.ubuntu.com/manpages/jammy/en/man1/gs.1.html

You should be able to test gs.sh ... in a test directory of your server using the script on a file that gs can convert.

As long as we are sharing 'creations':

#!/bin/bash
ls *.pdf;
echo 'Takes one parameter: filename with no .pdf extension';
echo 'Parameter given:' $1;
echo 'Paused ...';
read $keypress;
START=$(date +%s)

pageNum=`gs -q -dNODISPLAY -c "(./$1.pdf) (r) file runpdfbegin pdfpagecount = quit"`
gs -dNumRenderingThreads=4 -dNOPAUSE -sDEVICE=png16m -dSAFER -dDOINTERPOLATE -dGraphicsAlphaBits=4 -dTextAlphaBits=4 -dFirstPage=1 -sOutputFile=./image%d.png -r300 -q $1.pdf -c quit

END=$(date +%s)
DIFF=$(( $END - $START ))
echo "It took $DIFF seconds"
ls -l *.png *.pdf

Isn't there an option for poppler now? And if found, poppler will do the conversions?

In System Paths:
"Poppler is a PDF rendering library which includes the tool pdftoppm for converting PDF files to PNG. Performance is generally better than when using Ghostscript, particularly for large files. If available, pdftoppm will be used in preference to Ghostscript. On most Linux installs, the path can be left as /usr/bin/pdftoppm. Otherwise, you need to install the poppler-utils or poppler package, depending on your Linux distribution. On Windows it is provided by Cygwin installs."

 'SoS', Ken

In reply to Ken Task

Re: blank pages on grade report file pdf on latest 4.1.9+ (Build: 20240315) $version = 2022112809.07

by Lewi S. Kristianto (visiniaga) -
Hi Ken, thanks for feedback,
the problem is not with gs.sh, as this already can grade after downgrade assignfeedback_editpdf from moodle 4.1.9,
In reply to Lewi S. Kristianto (visiniaga)

Re: blank pages on grade report file pdf on latest 4.1.9+ (Build: 20240315) $version = 2022112809.07

by Ken Task -
Picture of Particularly helpful Moodlers
Well, all I can tell you is that I have a 4.1.9+ and I don't have gs.sh ... just gs ... and I don't have any issue with that screen ... and did not 'downgrade' that part of core code to get anything to work! ??????

'SoS', Ken

In reply to Ken Task

Re: blank pages on grade report file pdf on latest 4.1.9+ (Build: 20240315) $version = 2022112809.07

by Lewi S. Kristianto (visiniaga) -
result using gs.sh script above. having problem converting file, 
but using command convert is able to change format from jpg to pdf
lewi@pixelbookgo:~$ chmod 755 gs.sh
(arg: 1) ^C
lewi@pixelbookgo:~$ ./gs.sh 1709519595093\ \(1\).jpg 
ls: invalid option -- '-'
Try 'ls --help' for more information.
Takes one parameter: filename with no .pdf extension
Parameter given: 1709519595093 (1).jpg
Paused ...
GPL Ghostscript 10.00.0: Unrecoverable error, exit code 1 Error: /undefinedfilename in (1709519595093) Operand stack:
Execution stack: %interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push Dictionary stack: --dict:776/1123(ro)(G)-- --dict:0/20(G)-- --dict:75/200(L)-- Current allocation mode is local Last OS error: No such file or directory GPL Ghostscript 10.00.0: Unrecoverable error, exit code 1 It took 1 seconds ls: invalid option -- '-' Try 'ls --help' for more information. lewi@pixelbookgo:~$ convert 1709519595093\ \(1\).jpg 1709519595093\ \(1\).pdf lewi@pixelbookgo:~$
but I have missreported, found that I have cron to disable ghostscript /usr/bin/gs on certain hour to remove permission only to root, that cause this problem.
this prevent to have ghostscript running hogging for server process.



In reply to Lewi S. Kristianto (visiniaga)

Re: blank pages on grade report file pdf on latest 4.1.9+ (Build: 20240315) $version = 2022112809.07

by Ken Task -
Picture of Particularly helpful Moodlers
So the real problem is:
"...
ghostscript running hogging for server process
"
Isn't there a task in the task list specifically for preparing assignment submissions for annotation?

Check it's schedule.

And if that task is dragging down your server performance, is there anything you can do to increase memory allocated to the server?

And, does your server suggest using poppler?

'SoS', Ken
 
In reply to Ken Task

Re: blank pages on grade report file pdf on latest 4.1.9+ (Build: 20240315) $version = 2022112809.07

by Lewi S. Kristianto (visiniaga) -
yes, let me try with adding poppler-utils to instance group vm,
the problem is when ghostscript runs when quiz running concurrently for large student, vm hogging 100% for the cpu process.
as I read documentation, for pdftoppm is helping for the converting pdf to png only, not otherwise if students upload jpg and convert to pdf for grading right?
so I'm still monitoring, and prevent issues with using cpulimit -- limits the CPU usage of a process for the /usr/bin/gs and /usr/bin/pdftoppm

thanks Ken for the suggestion, and grade issue now found the root cause also
Average of ratings:Useful (1)
In reply to Ken Task

Re: blank pages on grade report file pdf on latest 4.1.9+ (Build: 20240315) $version = 2022112809.07

by Lewi S. Kristianto (visiniaga) -
gs.sh

#!/bin/sh
TIMEOUT=20
export TEMP=/tmp
LOGFILE=/tmp/gs-moodle.log
#/usr/bin/nice -n19 /usr/bin/timeout $TIMEOUT /usr/bin/gs $@
/usr/bin/nice -n19 /usr/bin/gs $@
returncode=$?
if [ "$returncode" -eq 124 ]; then
    echo "$(date -Iseconds) - GS command timed out: /usr/bin/gs $@" >> $LOGFILE
fi
exit $returncode
Attachment Screenshot_20240319_095831_Chrome.jpg