Issues with PDF files in the grading interface

Issues with PDF files in the grading interface

by Frederic Nevers -
Number of replies: 6

Hi, 

Most of the PDF files that my students upload as part of their assignment submissions cannot be opened in the grading interface. It used to work fine, and I cannot point to a single event that would be an obvious culprit (or a bunch of events for that matter). 

Here is what the error looks like (Moodle 3.1.4+). For Google, the message reads

Cannot open the PDF. The file may be corrupt, or in an unsupported format.


After a bit of digging, I found that GhostScript was not able to generate an image of the document. Apache error logs show the following message (similar message for all PDF files):

**** Error reading a content stream. The page may be incomplete.

GPL Ghostscript 9.06: Unrecoverable error, exit code 1

[Fri Feb 10 12:49:51.474866 2017] [:error] [pid 4419] [client 10.10.4.10:49606] Default exception handler: Error generating image with ghostscript, debugging info: <pre>Command:\n'/usr/bin/gs' -q -sDEVICE=png16m -dSAFER -dBATCH -dNOPAUSE -r'100' -dFirstPage='1' -dLastPage='1' -dDOINTERPOLATE -dGraphicsAlphaBits=4 -dTextAlphaBits=4 -sOutputFile='[tempdir]/assignfeedback_editpdf/pageimages/e30aede1e9465eef210d66e071a9562383d872bc/image_page0.png' '[tempdir]/assignfeedback_editpdf/pageimages/e30aede1e9465eef210d66e071a9562383d872bc/combined.pdf'\n\nResult:\nCurrent allocation mode is local\n\nOutput:\nError: /typecheck in --run--\nOperand stack:\n   --dict:13/13(L)--   --dict:63/63(ro)(L)--   PageSpotColors   --dict:13/13(L)--   --dict:0/0(L)--   --dict:4/4(L)--   --dict:5/5(L)--   --dict:4/4(L)--   9934387   385   0   --nostringval--   ShadingType   3   ColorSpace   DeviceRGB   Function   --dict:6/6(L)--   Coords   --nostringval--   0.004964   12   (0.00-6673972)   --nostringval--   --dict:12/12(ro)(G)--\nExecution stack:\n   %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   false   1   %stopped_push   1914   1   3   %oparray_pop   1913   1   3   %oparray_pop   1897   1   3   %oparray_pop   --nostringval--   --nostringval--   2   1   1   --nostringval--   %for_pos_int_continue   --nostringval--   --nostringval--   --nostringval--   --nostringval--   --nostringval--   %loop_continue   --nostringval--   --dict:70/70(L)--   --nostringval--   128   %dict_continue   --nostringval--   %loop_continue   --nostringval--   --dict:67/67(L)--   --nostringval--   5   %dict_continue   --nostringval--   %loop_continue   --nostringval--   --dict:1/1(L)--   --nostringval--   1   %dict_continue   --nostringval--   --nostringval--\nDictionary stack:\n   --dict:1175/1684(ro)(G)--   --dict:1/20(G)--   --dict:82/200(L)--   --dict:82/200(L)--   --dict:109/127(ro)(G)--   --dict:293/300(ro)(G)--   --dict:24/31(L)--   --dict:3/6(L)--\nCurrent allocation mode is local</pre> Debug: \nError code: errorgenerateimage\n* line 459 of /mod/assign/feedback/editpdf/classes/pdf.php: moodle_exception thrown\n* line 447 of /mod/assign/feedback/editpdf/classes/document_services.php: call to assignfeedback_editpdf\\pdf->get_image()\n* line 551 of /mod/assign/feedback/editpdf/classes/document_services.php: call to assignfeedback_editpdf\\document_services::generate_page_images_for_attempt()\n* line 69 of /mod/assign/feedback/editpdf/ajax.php: call to assignfeedback_editpdf\\document_services::get_page_images_for_attempt()\n, referer: https://moodle.isf.edu.hk/mod/assign/view.php?id=444&rownum=0&action=grader&userid=36

I have checked the GhostScript file (it's fine) and tested it, using the 'Test GhostScript path' admin tool, and that worked fine as well. I have also checked whether the PDFs were fine, and they all were (we're talking dozens of files). It happens in all assignments, not just mine. The weird thing is - some PDFs go through just fine (I cannot find any difference with the ones that work, and the ones that don't). I updated to 3.1.4 as there were some assignment-related fixes, but that has not worked.

The funny thing is that Unoconv works fine (took a while to get it going...). For example, if a student uploads a ppt file (or other type), it gets converted into whatever Unoconv converts it to (PDF?) and displays fine in the grading interface. Having said that, now that GhostScript is misbehaving, it prevents the assignfeedback_editpdf\\task\\convert_submissions from working properly (it hangs quietly and gets stuck on submissions that have a problem).

Does anybody have any idea what could be the problem? 

Cheers, 

Fred

Average of ratings: -
In reply to Frederic Nevers

Re: Issues with PDF files in the grading interface

by Ken Task -
Picture of Particularly helpful Moodlers

Do you have a listener setup for unoconv?

https://docs.moodle.org/31/en/Installing_unoconv

'spirit of sharing', Ken


In reply to Ken Task

Re: Issues with PDF files in the grading interface

by Frederic Nevers -

Hi Ken, 

Thank you for your reply. Yes I do, and it works well (it took a while to get it working, though). 

When I run the conversion task manually, I get the following errors for PDF files only (ppt, doc, etc. convert just fine)

Convert 1 submission attempt(s) for assignment 1998
   **** Error reading a content stream. The page may be incomplete.
GPL Ghostscript 9.06: Unrecoverable error, exit code 1
Conversion failed with error:errorgenerateimage
I am starting to wonder if there is a permissions problem somewhere, but none of the error messages I get suggest so. I'll see if I can convert documents using the command line, but I need to learn how to do it first!

Cheers, 

Fred

In reply to Frederic Nevers

Re: Issues with PDF files in the grading interface

by Ken Task -
Picture of Particularly helpful Moodlers

Would it be possible to see the file that created the error?  (attached to this thread)

GhostScript error

Error reading a content stream. The page may be incomplete.
GPL Ghostscript 9.06: Unrecoverable error, exit code 1
Conversion failed with error:errorgenerateimage


Reported bug

https://bugs.ghostscript.com/show_bug.cgi?id=696682

Response:

The problem is the resolution, setting resolution to 18 dpi (-r18) causes a shading pattern to collapse (results in a rangecheck error in makepattern) which the interpreter ignores. However, ignoring parts of the page simply causes problems later on and eventually this becomes unrecoverable.

Don't set the resolution to 18 dpi, 39 dpi is the lowest value which will work for this particular file.


In your error report via Moodle:

/usr/bin/gs' -q -sDEVICE=png16m -dSAFER -dBATCH -dNOPAUSE -r'100'

So that seems to indicate that whatever was submitted has issues with
the conversion.

Think you are going to have to try the gs command from command line on the file
that was submitted.

I see a 'typecheck in' then it list all the things checked?

--run--\nOperand stack:\n   --dict:13/13(L)--   --dict:63/63(ro)(L)--   PageSpotColors   --dict:13/13(L)--   --dict:0/0(L)--   --dict:4/4(L)--   --dict:5/5(L)--   --dict:4/4(L)--   9934387   385   0   --nostringval--   ShadingType   3   ColorSpace   DeviceRGB   Function   --dict:6/6(L)--   Coords   --nostringval--   0.004964   12   (0.00-6673972)   --nostringval--   --dict:12/12(ro)(G)--\nExecution stack:\n   %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   false   1   %stopped_push   1914   1   3   %oparray_pop   1913   1   3   %oparray_pop   1897   1   3   %oparray_pop   --nostringval--   --nostringval--   2   1   1   --nostringval--   %for_pos_int_continue   --nostringval--   --nostringval--   --nostringval--   --nostringval--   --nostringval--   %loop_continue   --nostringval--   --dict:70/70(L)--   --nostringval--   128   %dict_continue   --nostringval--   %loop_continue   --nostringval--   --dict:67/67(L)--   --nostringval--   5   %dict_continue   --nostringval--   %loop_continue   --nostringval--   --dict:1/1(L)--   --nostringval--   1   %dict_continue   --nostringval--   --nostringval--\nDictionary stack:\n   --dict:1175/1684(ro)(G)--   --dict:1/20(G)--   --dict:82/200(L)--   --dict:82/200(L)--   --dict:109/127(ro)(G)--   --dict:293/300(ro)(G)--   --dict:24/31(L)--   --dict:3/6(L)-

Google search:
https://www.google.com/search?q=typecheck+ghostscript+error&ie=utf-8&oe=utf-8

Looks like an error like this is going to be highly dependent on the file  that was submitted as well as the installation of ghostscript ... which is affected by platform.

gs --help

on a CentOS 5 box (soon to be retired) renders lots of information.  Same for CentOS 6.

In both:

Input formats: PostScript PostScriptLevel1 PostScriptLevel2 PostScriptLevel3 PDF

'spirit of sharing', Ken



In reply to Ken Task

Re: Issues with PDF files in the grading interface

by Nathan Rosenquist -

This thread is a few months old but adding my fix here in case anyone finds this via Google like I did:

Was running into the ghostscript 'Rangecheck' crash during the document conversions task, I'm guessing on only about 1 in 1000 conversions or so but that was frequent enough for it to become a major pain point for us. Our server was running gs version 8.7 (Version installed by yum from epel repos on CentOS 6.8). Downloading and compiling version 9.21 from the ghostscript git, and replacing v8.7 with v9.21, fixed the issue. If you're on Fedora/RHEL-flavored Linux and compiling from source scares you, this script will do the heavy lifting:

#!/bin/bash

yum install git
git clone --branch gs921 git://git.ghostscript.com/ghostpdl.git
cd ghostpdl
./autogen.sh
./configure
make
make install
mv /usr/bin/gs /usr/bin/gs.87
mv /usr/bin/local/gs /usr/bin/gs

exit 0

In reply to Frederic Nevers

Re: Issues with PDF files in the grading interface

by Ken Task -
Picture of Particularly helpful Moodlers

unoconv and ghostscript test scripts and files

Anyone with link can view.

https://drive.google.com/open?id=0B5gmU8YqbNJQaFRFWHluSXhzaDQ

Two files ... one .zip and one .tar
The readme that's included with both archives:

https://drive.google.com/drive/folders/0B5gmU8YqbNJQaFRFWHluSXhzaDQ

'spirit of sharing', Ken

In reply to Ken Task

Re: Issues with PDF files in the grading interface

by Frederic Nevers -

Thank you, Ken. It appears that an upgrade of both Ghostscript and Moodle seems to have solved the issue. I am not sure what happened 'under the hood' that fixed our issue, but it did to the trick. 

Thanks for your help. 

Cheers, 

Fred