Cannot open PDF error in grading

Cannot open PDF error in grading

by Jas Green -
Number of replies: 40

Hello,

We are getting this error when trying to grade: Cannot open the PDF. The file may be corrupt, or in an unsupported format.

http://eagleacademy.com.au/onlinelearningcentre/mod/assign/view.php?id=668&action=grader

Our developer told us we needed to instal unoconv on the server. The IT company believe that they have now done that successfully but we're still getting this error. 

Any tips for the developer/IT company on how to get it to work?

This error started appearing when we upgraded from 3.3.2 to 3.5. 

Thanks,

Jas

Average of ratings: Useful (1)
In reply to Jas Green

Re: Cannot open PDF error in grading

by Abraham Tamez -

I have the same problem, tried to fixed it with google converter, the plugin works fine, but i have the same error code. 

In reply to Abraham Tamez

Re: Cannot open PDF error in grading

by Oliver Boyers -

I have the same error in Moodle 3.5.2. 

Unoconv installed correctly. 

Only occurring when word documents are uploaded and need to be converted to pdf. 

In reply to Oliver Boyers

Re: Cannot open PDF error in grading

by Cosmas Kasumba -
Picture of Testers
Did ou manage to get it fixed. Am having the same error. :
In reply to Cosmas Kasumba

Re: Cannot open PDF error in grading

by Go Click On -

Hi Everyone,

I getting below error under the assignment grade module

I tested ghostscript but its return error like below


Error generating image with ghostscript, debugging info:

Command:
'/usr/bin/ghostscript' -q -sDEVICE=png16m -dSAFER -dBATCH -dNOPAUSE -r'100' -dFirstPage='1' -dLastPage='1' -dDOINTERPOLATE -dGraphicsAlphaBits=4 -dTextAlphaBits=4 -sOutputFile='/home/dolphedu/moodledata/temp/assignfeedback_editpdf_test/image_page0.png' '/home/dolphedu/public_html/moodle/mod/assign/feedback/editpdf/tests/fixtures/testgs.pdf'

Result:


Output:
any one can help for how to resolve this error?

Regards

Alpesh

In reply to Go Click On

Re: Cannot open PDF error in grading

by Go Click On -
If I run this script directly in SSH then it's working good

Command:
'/usr/bin/ghostscript' -q -sDEVICE=png16m -dSAFER -dBATCH -dNOPAUSE -r'100' -dFirstPage='1' -dLastPage='1' -dDOINTERPOLATE -dGraphicsAlphaBits=4 -dTextAlphaBits=4 -sOutputFile='/home/dolphedu/moodledata/temp/assignfeedback_editpdf_test/image_page0.png' '/home/dolphedu/public_html/moodle/mod/assign/feedback/editpdf/tests/fixtures/testgs.pdf'
In reply to Go Click On

Re: Cannot open PDF error in grading

by Emma Richardson -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers
Have you added the ghostscipt location in your moodle admin settings?
In reply to Emma Richardson

Re: Cannot open PDF error in grading

by Go Click On -

Yes I added Ghostscript in location

but when I test it it's getting an error.

In reply to Go Click On

Re: Cannot open PDF error in grading

by Ken Task -
Picture of Particularly helpful Moodlers

The test

/home/dolphedu/moodledata/temp/assignfeedback_editpdf_test/image_page0.png' '/home/dolphedu/public_html/moodle/mod/assign/feedback/editpdf/tests/fixtures/testgs.pdf'

converts a 'paged' png (graphic) to the tests.pdf file.

which isn't the same as working with a .docx.

Since you have command line access, go to:

/home/dolphedu/moodledata/temp/assignfeedback_editpdf_test/

and see what's really there.  Should be a image_page0.png file.

Check it with file -b image_page0.png

Remove it manually.

Test isn't same as working with a .docx or other file type.

Check settings of assignment ... especially the file type students are allowed to submit.   The entire process dependent upon the student upload.  Might go to assignment itself and download the file student submitted.

There is also a task related ... defaults to run ASAP.  Set path to php-cli so you can see the 'run now' link under that task.  Since you are having issues, click the 'run now' to see how that specific task is performing.

Since you shared the fact that hosting provider had to install ghostscript for you kinda indicates you might have an under-powered server.

From ssh, what does the top of the 'top' command look like?

Lot's of other things potentially to look at, so we'll start with above.

'SoS', Ken


In reply to Ken Task

Re: Cannot open PDF error in grading

by Go Click On -

Hi Ken,

I check "image_page0.png" is not exist on below location

/home/dolphedu/moodledata/temp/assignfeedback_editpdf_test

Also,  If I run below command using SSH then the image is successfully generated from pdf to png on the above location.

Command:
'/usr/bin/ghostscript' -q -sDEVICE=png16m -dSAFER -dBATCH -dNOPAUSE -r'100' -dFirstPage='1' -dLastPage='1' -dDOINTERPOLATE -dGraphicsAlphaBits=4 -dTextAlphaBits=4 -sOutputFile='/home/dolphedu/moodledata/temp/assignfeedback_editpdf_test/image_page0.png' '/home/dolphedu/public_html/moodle/mod/assign/feedback/editpdf/tests/fixtures/testgs.pdf'

That's mean Ghostscript is working well.

Is there any other possible issue?


In reply to Go Click On

Re: Cannot open PDF error in grading

by Ken Task -
Picture of Particularly helpful Moodlers
when you ran the command via ssh, were you logged on as root, or another use?   whoami

"Check settings of assignment ... especially the file type students are allowed to submit.   The entire process dependent upon the student upload.  Might go to assignment itself and download the file student submitted.

There is also a task related ... defaults to run ASAP.  Set path to php-cli so you can see the 'run now' link under that task.  Since you are having issues, click the 'run now' to see how that specific task is performing.

Since you shared the fact that hosting provider had to install ghostscript for you kinda indicates you might have an under-powered server.

From ssh, what does the top of the 'top' command look like?"

'SoS', Ken

In reply to Ken Task

Re: Cannot open PDF error in grading

by Go Click On -

"Check settings of assignment ... especially the file type students are allowed to submit.   The entire process dependent upon the student upload.  Might go to assignment itself and download the file student submitted.

Answer


Since you shared the fact that hosting provider had to install ghostscript for you kinda indicates you might have an under-powered server.

Answer
[root@ssh-lin-us1 local]# which ghostscript
/usr/bin/ghostscript

There is also a task related ... defaults to run ASAP.  Set path to php-cli so you can see the 'run now' link under that task.  Since you are having issues, click the 'run now' to see how that specific task is performing.

 - I do not understand about it. can you explain me in detail?

In reply to Go Click On

Re: Cannot open PDF error in grading

by Ken Task -
Picture of Particularly helpful Moodlers
Go to your servers:
/admin/tool/task/scheduledtasks.php
IF you have set the path for php-cli there will be a 'run now' link under the task for the very first task listed which is:
Prepare submissions for annotation \assignfeedback_editpdf\task\convert_submissions

I see by your login info above you are in your system as root and you've provided info on path to ghostscript.
Please login and type: top [ENTER]
Copy and paste from the 'top' of the 'top' command .... looks like
top - 08:16:17 up 26 days, 10:58, 1 user, load average: 0.13, 0.08, 0.05
Tasks: 148 total, 1 running, 147 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.0 us, 0.0 sy, 0.0 ni, 99.9 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 8003380 total, 355752 free, 1733064 used, 5914564 buff/cache
KiB Swap: 0 total, 0 free, 0 used. 5442320 avail Mem
In reply to Ken Task

Re: Cannot open PDF error in grading

by Go Click On -
I clicked on "run now" link then i got below output.



I am not understanding second part of your quesiton. Can you explain in more details?
In reply to Go Click On

Re: Cannot open PDF error in grading

by Ken Task -
Picture of Particularly helpful Moodlers

Well, you can see the task failed ... with error ... right?

Each submission failed to convert.

Second part ...

OK how about this ...

Login as root.

From the shell prompt, type: top [PRESS ENTER]

Make a screen shot!

'Sos', Ken


In reply to Go Click On

Re: Cannot open PDF error in grading

by Ken Task -
Picture of Particularly helpful Moodlers

Can you check your Litespeed's web service error logs?

See also server has cPanel.

Don't think there are many in these forums that use Litespeed, thus perhaps one of your resources for trouble shooting issues is:

https://www.litespeedtech.com/support/forum/

May as well ask ... what operating system?  Linux?  Ubuntu/CentOS other?

Not being nosey ... if you look at recommendations for forums and what information to share up front about server, those seamingly unrelated really might be related.

'SoS', Ken


In reply to Ken Task

Re: Cannot open PDF error in grading

by Go Click On -
We are using CentOs with cloud linux.
I checked error log but it's show no any error

In reply to Go Click On

Re: Cannot open PDF error in grading

by Ken Task -
Picture of Particularly helpful Moodlers

Looks like a cPanel clip.

There could be other error logs which don't combine with litespeed's logs.

CentOS 7 but with 'cloud linux' ... so it's not 'stock' CentOS 7.  I've got a couple of 'stock' sites and don't have the issue.

So what other protections does your server have?

One of the things that causes issues with CentOS 7 sometimes is a thing called 'seLinux' ... security enhanced ... it might not log errors to Litespeed logs but to logs of it's own.

Typically, if one had root access to server (which you shared with me in a PM you do not, and you are acting as a go-between to those who do), a command exist to see if seLinux is set to enforcing.

sestatus [ENTER]

Your server might also have other protections ... like apache's mod_security, or securi or suPHP or ????

Basically, when moodle attempts to generate a png image of whatever is being converted, it relies upon ghostscript (gs) to do that ... the path you enter might show a 'check' ... meaning it found gs at path given, but that won't tell you if Moodle can actually run it ... in your servers case, Moodle code can't - we've proven that.

Why do I get the feeling am trying to teach your hosting providers tech support via proxy (ie, you)?

Maybe, hosting providers tech support should join the forums - if they are gonna tell customers, ie, you, their servers can run moodles, then it suggest they have some knowledge of moodle.

'SoS', Ken

In reply to Ken Task

Re: Cannot open PDF error in grading

by Jeffery Watkins -
Hi Ken,

I am having the exact same problem, but only on one server. SELinux is set to permissive, so I do not think it is that, But cPanel users (the moodle site) cannot run the GS command, but I can from shell. This server is running PHP 7.2.29.

Happy to provide any info I can to help solve this. I am stumped.

Jeff
In reply to Jeffery Watkins

Re: Cannot open PDF error in grading

by Ken Task -
Picture of Particularly helpful Moodlers

SELinux complaints in logs do give a clue.

cPanel user ... don't know what that means.   Ownerships/permissons on files in code are like what?

If you can run from shell, how are you logged on?  Did you su to root to run it?  Did you sudo to user of code scripts and run the same command?

Could turn off annotation in Feedback settings (course level and site level).  Doing that no doc/file submitted should be converted to a PDF but teacher than has only comments in moodle and to actually view a file has to download to open.

Also, higher versions of Moodle have new settings for Assignments that are not automagically set after an upgrade.   Each Assignment has to be visited and mimetypes/filetypes allowed settings need to be set ... might see nothing in the box for that setting now and I don't know if Moodle smart enough to defaiult to * ... all.   Probably best to set to something otherwise teacher might not have software to open the file ... thus can't grade.

Document conversion via unoconv has been problematic ... have you thought about using Google?

'SoS', Ken


In reply to Ken Task

Re: Cannot open PDF error in grading

by Jeffery Watkins -
Hi Ken,

I am logged in as root.

Permissions for ghostscript: lrwxrwxrwx. 1 root root 2 Dec 8 2018 ghostscript -> gs

By cPanel user, I mean the account user. So the various moodle sites on this server are all a different cPanel user account.

In shell, if I run the script as root, it works. If I su to one of the user accounts and run it, it works. It just does not work from Moodle interface. Something with Apache permissions to run the script maybe?

The allowed filetypes setting is correct.

Jeff
In reply to Jeffery Watkins

Re: Cannot open PDF error in grading

by Ken Task -
Picture of Particularly helpful Moodlers

' ...the various moodle sites on this server ..."

How many moodle sites?  Thus can't give definitive answer.

All of those sites use the same ghostscript although the process saves files
in different moodledata directories.  What's top look like?

One assignment can jam up the process.
There is a task for prepping the assignments files uploaded to PDF for when
teacher decides to grade.

task:

/admin/tool/task/scheduledtasks.php
first one listed:
Prepare submissions for annotation \assignfeedback_editpdf\task\convert_submissions
is defaulted to run */15

data directory location

moodledata/temp/assignfeedback_editpdf
and contained therein
final
pageimages
stamps

On one busy K12 server had to disable annotated feedback ... teachers weren't really using anyway.  Problem went away.

'SoS', Ken


In reply to Go Click On

Re: Cannot open PDF error in grading

by Ken Task -
Picture of Particularly helpful Moodlers

The test just does a test ... and from pdf to png.

In the assignment you've limited student uploads to one of three (accepted file types:
.docx,.doc,.pdf

IF you want to test ghostscript for those file types, you'll have to find
the command for each document type.

For that, one can use:
https://www.ghostscript.com/doc/current/Use.htm

I personally find the annotation tool clunky and not easy to use.  Your teachers might think the same.

Thus, might be best to turn it off and the only feedback teachers can give
are in comments.  Means teacher would have to download whatever file to view locally.

/mod/assign/adminmanageplugins.php?subtype=assignfeedback

/category.php?category=modassignfolder

'SoS', Ken

In reply to Go Click On

Re: Cannot open PDF error in grading

by Cosmas Kasumba -
Picture of Testers
Hi manoj gusain,
Yes mine was solved, the problem I had was ghostscript, I had left on the default path in moodle but when I checked with the host, the path being used on the server was completely different. I had to update the path in moodle so that it is the same as on the server, I would advise you ask your host if you are not hosting yourself for the paths to the script on the server. Just a note, when I enquired I was initially told by the host that managing of scripts is not part of our agreement, I had to tell the person who was assisting me that I didn't want him to configure the scripts but rather to provide me with the paths to the scripts.(I use hostgator by the way)
In reply to Cosmas Kasumba

Re: Cannot open PDF error in grading

by manoj gusain -
thankyou cosmos for reply i appreciate i am using inmotion hosting also i ask them they told me the path /usr/bin/ghostscript also i check which ghostscript also give same path which i put in system path and it show me tick sign means its correct but when i test ghostscript it give me error

Error generating image with ghostscript, debugging info:
Command:
'/usr/bin/gs' -q -sDEVICE=png16m -dSAFER -dBATCH -dNOPAUSE -r'100' -dFirstPage='1'
-dLastPage='1' -dDOINTERPOLATE -dGraphicsAlphaBits=4 -dTextAlphaBits=4 -sOutputFile
='/home/wwwelearnplace/educationmoodledata/temp/assignfeedback_editpdf_test/image_page0.png
' '/home/wwwelearnplace/public_html/education/mod/assign/feedback/editpdf/tests/fixtures/testgs.pdf'

now any solution?
In reply to manoj gusain

Re: Cannot open PDF error in grading

by Ken Task -
Picture of Particularly helpful Moodlers

Paths seen in config hints are not discovered ... they are suggestions.
To know for sure, the command which ghostscript command should show that path for user's environment.  Let's say servers web service user is 'apache', try this command to see about path/environment:

sudo -u apache which ghostscript

On a CentOS 7 box, that shows:

/bin/ghostscript

and if one ls -l /bin/ghostscript

One might see it's an alias:

[root@server]# ls -l /bin/ghostscript
lrwxrwxrwx. 1 root root 11 Dec  3 14:55 /bin/ghostscript -> /usr/bin/gs

If you note your debug output ... /usr/bin/gs isn't /usr/bin/ghostscript

cd /usr/bin/
ls -l gs

Is that an alias?   IF so you will see a -> /usr/bin/ghostscript
IF not an alias, it means changes to config of moodle paths did not take for some reason.

IF you have /usr/bin/ghostscript.

Can force the path you want by adding a $CFG line to config.php

$CFG->pathtogs="/usr/bin/ghostscript";

Also make sure your moodledata/temp/ directory has liberal read/write permissions

Does your site run any web application firewall?  Securi, mod_security, or if CentOS is selinux set to enforcing and preventing writing of file to moodledata?

'SoS', Ken

In reply to Ken Task

Re: Cannot open PDF error in grading

by manoj gusain -

thankyou for reply but i cant understand so much i am sending you everthing here please let me know if you find any solution

which ghostscript give me path  /usr/bin/ghostscript

cd /usr/bin

ll

lrwxrwxrwx   1 root root          11 Dec  4 10:05 ghostscript -> /usr/bin/gs*

above is the output 

so now tell me the path is  /usr/bin/ghostscript or /usr/bin/gs  ?????

even i tried putting both path to test ghostscript but i saw same error as above

Error generating image with ghostscript, debugging info:

Command:
'/usr/bin/gs' -q -sDEVICE=png16m -dSAFER -dBATCH -dNOPAUSE -r'100' -dFirstPage='1' -dLastPage='1' -dDOINTERPOLATE -dGraphicsAlphaBits=4 -dTextAlphaBits=4 -sOutputFile='/home/wwwelearnplace/educationmoodledata/temp/assignfeedback_editpdf_test/image_page0.png' '/home/wwwelearnplace/public_html/education/mod/assign/feedback/editpdf/tests/fixtures/testgs.pdf'

Result:
also after this when i click continue i go to the page where i see something error just check the screenshot i send you

also i give read /write permission to  /educationmoodledata/temp/assignfeedback_editpdf_test even not get any result 

the main problem is ghostscript once the path is correct then it work but i cant understand what is the problem??

also check its

root@vps [~]# whereis ghostscript

ghostscript: /usr/bin/ghostscript /usr/lib64/ghostscript /etc/ghostscript /usr/include/ghostscript /usr/share/ghostscript /usr/share/man/man1/ghostscript.1.gz


educationmoodledata/temp/assignfeedback_editpdf_test
 
educationmoodledata/temp/assignfeedback_editpdf_test
educationmoodledata/temp/assignfeedback_editpdf_test


Attachment Screenshot (19).png
In reply to manoj gusain

Re: Cannot open PDF error in grading

by manoj gusain -

please anyone can help its urgent what should i do? changing hosting provider can help??

In reply to manoj gusain

Re: Cannot open PDF error in grading

by Lewis Kariuki -
Hello,

From my experience on Ubuntu the below is the process I used and worked for me:-

begun by install ghostscript from the terminal
  
   sudo apt install ghostscript

then downloaded the Ghostscript file from the ghostscript site https://www.ghostscript.com/download/gsdnld.html using the below

    wget https://www.ghostscript.com/download/gsdnld.html

then extracted
     tar -zxvf ghostscript-9.18-linux-x86_64.tgz
     cd ghostscript-9.18-linux-x86_64

then moved the extracted file to the installation path of gs

     sudo cp gs-918-linux_x86_64 /usr/bin/gs

     sudo chmod +x /usr/bin/gs

then update the path on moodle then tested
test output

hope this help..


In reply to Go Click On

Re: Cannot open PDF error in grading

by manoj gusain -

exactly i have same issue whatever you have can you help me please still having this problem did you solved it??

In reply to manoj gusain

Re: Cannot open PDF error in grading

by Vladimír Výboh -

exactly i have same issue whatever you have can you help me please still having this problem did you solved it??

Moodle 3.8.5+

In reply to Vladimír Výboh

Re: Cannot open PDF error in grading

by Nik M -
Have you checked your host/php.ini is not blocking exec()? 
In reply to Nik M

Re: Cannot open PDF error in grading

by Felipe Reis -
I'm having the same issue, but in my case, when I run that command by terminal server, it work and create the file at directory below. Even so the moodle does not run this command.
'/usr/bin/gs' -q -sDEVICE=png16m -dSAFER -dBATCH -dNOPAUSE -r'100' -dFirstPage='1' -dLastPage='1' -dDOINTERPOLATE -dGraphicsAlphaBits=4 -dTextAlphaBits=4 -sOutputFile='/home/eduitarc/moodledata/temp/assignfeedback_editpdf_test/image_page0.png' '/home/eduitarc/public_html/mod/assign/feedback/editpdf/tests/fixtures/testgs.pdf'
Somebody could give me a light here?
In reply to Nik M

Re: Cannot open PDF error in grading

by Felipe Reis -
Yes!!!!
It's work now. Was exactly what you said Nik. Thanks a lot!
In reply to Felipe Reis

Re: Cannot open PDF error in grading

by Melanie Treitinger -
I have the same problem! I have checked:

1) Ghostscript is installed and working: "sudo -u www-data '/usr/bin/gs' ..." produces the desired file
2) Moodle shows the ghostscript smiley
3) php.ini is not blocking the exec() function

Any ideas what is missing?
In reply to Melanie Treitinger

Re: Cannot open PDF error in grading

by Melanie Treitinger -
I most likely have found the cause:
We had a problem with our nfs file storage, so the requested file was not created in the moodledata dir when the file was uploaded.

Workaround:
In the grading overview ("View all submissions") click on the arraw next to "Edit" and then on "Allow submission changes".
Click on the arrow again and choose "Edit submission". Next click on "save changes" (no need to do anything else).
When you click on "Grade" in the submission overview again, the pdf is loaded correctly.
In reply to Nik M

Re: Cannot open PDF error in grading

by Richard Jiménez Ortega -
(Spanish)

¡Excelente!

Logré arreglar mi problema con ghostscript

Uso cPanel, y necesité quitar exec de disable_functions

ERROR:

Warning: implode(): Invalid arguments passed in /home/claseinteligente/public_html/campus/mod/assign/feedback/editpdf/classes/pdf.php on line 570

Error generating image with ghostscript, debugging info:

Command:
'/usr/bin/gs' -q -sDEVICE=png16m -dSAFER -dBATCH -dNOPAUSE -r'100' -dFirstPage='1' -dLastPage='1' -dDOINTERPOLATE -dGraphicsAlphaBits=4 -dTextAlphaBits=4 -sOutputFile='/home/.../moodledata/temp/assignfeedback_editpdf_test/image_page0.png' '/home/.../public_html/.../mod/assign/feedback/editpdf/tests/fixtures/testgs.pdf'

Result:


Output:

SOLUCIÓN:



para usuarios Cpanel, instrucciones para quitar exec de disable_functions Aquí


¡Muchas Gracias Nik!
In reply to Go Click On

Re: Cannot open PDF error in grading

by Buang M. Yulianto -

it just exactly happened to our system, by this morning user can not open pdf annotation. what we do and finally solved this problem are:
FYI our system description contain
Linux xxx-srv.local 3.10.0-1160.49.1.el7.x86_64
PHP 7.3.33 (cli) (built: Nov 29 2021 06:22:05) ( NTS )
Moodle 3.8.3+ (Build: 20200519)
GPL Ghostscript 9.25 (2018-09-13)

precaution:
- ghostscript can not run on selinux: enforce and permissive mode so it must be disabled and reboot the server
- i do run this script without disable_function on php
#how to check selinux status
sestatus
SELinux status:                 disabled
#edit selinux config file and set to disabled
nano /etc/selinux/config
SELINUX=disabled

save and reboot
#after distribution upgrade or package update make sure doublecheck on selinux status

#check ghostscript path and make sure it is correct
go to site administration > search: ghostscript > system paths > /usr/bin/gs
#double check on directory path:
ls -l ghostscript
lrwxrwxrwx. 1 root root 11 Jan 12 09:58 /usr/bin/ghostscript -> /usr/bin/gs
#if there is no ghostscript installed do install with yum install -y ghostscript.x86_x64
#do check on test gostscript path link
#if The ghostscript path appears to be OK - please check you can see the message in the image below it means ghostscript is OK

In reply to Cosmas Kasumba

Re: Cannot open PDF error in grading

by João Filipe Oliveira -

I get this error when a student submits an image from Google Drive. I must login to my GDrive and then I can download the image, but still get the same moodle error.

In reply to João Filipe Oliveira

Re: Cannot open PDF error in grading

by Pablo Hernández -
Hello João,

Wonder if you managed to find a solution/workaround for this? It is also happening to me only when students submit linked images from Google Drive, otherwise it works withou issue. Appreciate any info you could share. Thank you