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

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

by Dave Weninger -
Number of replies: 29

Dear Sir,

The teacher complained that she has added a lot of assignment activity. Students submitted their assignment as usual. When she review their assignment, she click "View all submissions" and then click "Grade" at the table after reading the assignment. Unfortunately, it prompts "Cannot open the PDF. The file may be corrupt, or in an unsupported format." She cannot give the score.

Please advise what is happening. How can I fix the problem?

Thank you very much.

Regards,

Kelvin Ma


Average of ratings: -
In reply to Dave Weninger

Re: Error message "Cannot open the PDF. The file may be corrupt, or in an unsupported format."

by Dave Weninger -

Attached is the screenshot.

Our moodle is version 3.6.1, CentOS 7, PHP 7.x

Attachment Cannot Open PDF.JPG
In reply to Dave Weninger

Re: Error message "Cannot open the PDF. The file may be corrupt, or in an unsupported format."

by Helen Foster -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Hi Kevin,

Please check that the path to ghostscript is set correctly on your site.

Average of ratings: Useful (2)
In reply to Helen Foster

Re: Error message "Cannot open the PDF. The file may be corrupt, or in an unsupported format."

by Dave Weninger -
Our Moodle does not have ghostscript installed. How can I set the path?
I type:
find / -name ghostscript
or, find / -name gs
nothing response

Another strange thing is that only those assignment created by the teacher has this error message.
I have tried to add an assignment and submit a test document. No error message prompts. Only the right hand side part is shown, Attached is the screenshot.

Please advise, Thanks!
Attachment normal_assignment (1).JPG
In reply to Dave Weninger

Re: Error message "Cannot open the PDF. The file may be corrupt, or in an unsupported format."

by Ken Task -
Picture of Particularly helpful Moodlers

As root user, use package manager for your OS ... which should be yum (CentOS 7):

yum -y install ghostscript.x86_64

Should install in /usr/bin/

which ghostscript will show path

Use that path in Moodle settings for paths.

No need to restart services.

You can check all paths set in moodle via admin/cli/php.cfg like so from moodle code directory:

php admin/cli/cfg.php |grep path

'SoS', Ken

Average of ratings: Useful (1)
In reply to Ken Task

Re: Error message "Cannot open the PDF. The file may be corrupt, or in an unsupported format."

by Dave Weninger -
It works! Thank you very much.
In reply to Ken Task

Re: Error message "Cannot open the PDF. The file may be corrupt, or in an unsupported format."

by Bang Rom -

sir how abaout if I install on cpanel?

how i can enable ghostscript??

In reply to Bang Rom

Re: Error message "Cannot open the PDF. The file may be corrupt, or in an unsupported format."

by Ken Task -
Picture of Particularly helpful Moodlers

'install on cPanel' ... does cPanel allow installation of operating system software/utilities?

Didn't think cPanel did.  How you install software depends upon operating system and what sort of hosting you have leased.

If operating system is Ubuntu, package manager (software installer) is apt-get.   If Centos 6 or 7, it's yum.

One really doesn't 'enable' ghostscript but setting path (as described in previous posting in this thread) is required.

'SoS', Ken

In reply to Ken Task

Re: Error message "Cannot open the PDF. The file may be corrupt, or in an unsupported format."

by Bang Rom -
I rented a hosting service

I think they do not activate the Ghostscript feature

so is there no other way?
In reply to Bang Rom

Re: Error message "Cannot open the PDF. The file may be corrupt, or in an unsupported format."

by Ken Task -
Picture of Particularly helpful Moodlers

Hosting providers don't normally go into Moodle to configure anything (enable/activate).   Moodle will use if path is entered and moodle code can see it/find it.  

If you have nothing to install software, you could ask your hosting provider to install ghostscript, but if on *shared* hosting, provider might tell you they cannot/will not.

Provider will probably suggest upgrading from *shared hosting*.

You've not shared with what provider not what plan you've leased so no other way of which am aware.

'SoS', Ken


In reply to Ken Task

Re: Error message "Cannot open the PDF. The file may be corrupt, or in an unsupported format."

by manoj gusain -

hi ken and everyone i have same problem  

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


i check system path of ghostscript  that is  /bin/usr/ghostscript its show me check sign means its correct but when i test ghostscript it show 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'

can't find the proper solution is something wrong with ghostscript or need to fix something in any file or folder

we are done this in vps hosting provider server centos 7 i check which ghostscript it give me path /usr/bin/ghostscript

version is 9.25

also /home/wwwelearnplace/educationmoodledata/temp/assignfeedback_editpdf_test/image_page0.png

their is no image_page0.png  that is empty?

 what should i do i dont understand can anyone help please

TOP coomand output

top - 02:57:30 up 34 days,  5:32,  1 user,  load average: 0.79, 0.56, 0.47

Tasks: 107 total,   1 running, 106 sleeping,   0 stopped,   0 zombie

%Cpu(s):  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st

KiB Mem :  8388608 total,  2574292 free,  2627668 used,  3186648 buff/cache

KiB Swap:        0 total,        0 free,        0 used.  5331476 avail Mem


  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND

10172 root      20   0  160004   4452   3808 R   0.3  0.1   0:00.04 top

10204 sshd      20   0  112924   6292   5236 S   0.3  0.1   0:00.01 sshd

    1 root      20   0  212424  25500   3324 S   0.0  0.3  24:16.61 systemd

  124 dbus      20   0   59052   1956    844 S   0.0  0.0  14:37.00 dbus-daemon

  287 root      20   0   45720  11920   4772 S   0.0  0.1   0:47.33 queueprocd+

  746 root      20   0  129448   5336   4572 S   0.0  0.1   1:17.90 dnsadmin -

In reply to Ken Task

Re: Error message "Cannot open the PDF. The file may be corrupt, or in an unsupported format."

by Lukman Adi -

can i get the video tutorial, sir? thanks

In reply to Lukman Adi

Re: Error message "Cannot open the PDF. The file may be corrupt, or in an unsupported format."

by Ken Task -
Picture of Particularly helpful Moodlers

Dunno who 'sir' is ... but ...

https://www.youtube.com/c/moodle

'SoS', Ken

In reply to Ken Task

Re: Error message "Cannot open the PDF. The file may be corrupt, or in an unsupported format."

by Lukman Adi -
sorry sir, i mean is video tutorial for this :

As root user, use package manager for your OS ... which should be yum (CentOS 7):

yum -y install ghostscript.x86_64

Should install in /usr/bin/

which ghostscript will show path

Use that path in Moodle settings for paths.

No need to restart services.

You can check all paths set in moodle via admin/cli/php.cfg like so from moodle code directory:

php admin/cli/cfg.php |grep path

thanks a lot
In reply to Lukman Adi

Re: Error message "Cannot open the PDF. The file may be corrupt, or in an unsupported format."

by Ken Task -
Picture of Particularly helpful Moodlers

Those are commands issued from an ssh shell session on server.   They are not anything used in URL line of a browser.

If you have CentOS 7, can ssh into your server and su to root, then one can simply copy and paste the commands.  Video of such things would be exceptions.

Must be a reason you are asking ... please explain why you'd need a video of such?

'SoS', Ken


In reply to Ken Task

Re: Error message "Cannot open the PDF. The file may be corrupt, or in an unsupported format."

by Lukman Adi -

sorry mr ken, I don't understand the part, You can check all paths set in moodle via admin / cli / php.cfg 

like so from moodle code directory: 

php admin / cli / cfg.php | grep path 

I have successfully installed ghostscript, and the path is correct, it's just that I don't understand how after that

what's the next step after this? thanks 

root
In reply to Lukman Adi

Re: Error message "Cannot open the PDF. The file may be corrupt, or in an unsupported format."

by Ken Task -
Picture of Particularly helpful Moodlers

Am gonna guess you are using Putty on Windows for copy and paste into a ssh shell on a Linux server.   That right?

Anytime one uses copy from something and paste into putty one has to be exacting with the copy end ... no extra lines, no extra characters, no left off characters.   Cause the operation with Putty is simply to 'right click' which sticks whatever is in the clipboard of your PC to the command line ... and Putty also presses enter for ya if I re-call correctly (haven't used Windows and Putty in years).   Nice if you copy accurately.   Not so nice if you don't.

See by your screen shot ... didn't get the ending 't' in first command you used thus an error.   Second is correct.

There is a php script in moodlecode/admin/cli/ called 'cfg.php' and it shows all the settings or ones you grep for.

So cd /path/to/moodlecode/admin/cli/

php cfg.php |grep path

should show settings in moodle for paths.

And, the one you are checking is the path to ghostscript.

That help?

'SoS', Ken


In reply to Ken Task

Re: Error message "Cannot open the PDF. The file may be corrupt, or in an unsupported format."

by Lukman Adi -

right mr ken..hehe , 

thank you for the advice
but still an error after instaling ghostsricpt


koreksian

but if I make a new assignment and upload a pdf file the preview won't appear
jj


In reply to Lukman Adi

Re: Error message "Cannot open the PDF. The file may be corrupt, or in an unsupported format."

by Ken Task -
Picture of Particularly helpful Moodlers

In your screen shot, looks like Ghostscript it trying to make a PDF from the PDF file submitted Tigas 4.1 psomething.pdf - if that PDF file not compatible or is corrupt, then ghostscript can't render it.

Suggest downloading and opening.

Might also have to do a query of your mdl_files table looking for that pdf file name along with it's contenthash value.

Then use contenthash value to find the actual file in moodledata/filedir/

copy that file (contenthashed named) out to some location where can download it to see that way also.

'SoS', Ken

In reply to Ken Task

Re: Error message "Cannot open the PDF. The file may be corrupt, or in an unsupported format."

by Ken Task -
Picture of Particularly helpful Moodlers

Follow up how 2 ... you change PDF file name to the one shown in your screen shot ...

Finding that pdf file in DB meta data ...

mysql> select filename,filesize,contenthash from mdl_files where filename like '%.pdf';

Example: cheat_sheet_linux_common_commands.pdf is the name of the uploaded PDF.

| cheat_sheet_linux_common_commands.pdf |   103630 | 9d71038ec1cab47d097b13e468824ea9ad63ac3c |

contenthash for that file is:

9d71038ec1cab47d097b13e468824ea9ad63ac3c

To find that file in moodledata/filedir/
cd moodledata/filedir/

find ./ -name 9d71038ec1cab47d097b13e468824ea9ad63ac3c

will return something like this:

./9d/71/9d71038ec1cab47d097b13e468824ea9ad63ac3c

copy that file out to web root (/var/www/html/) as a test.pdf file:

cp ./9d/71/9d71038ec1cab47d097b13e468824ea9ad63ac3c /var/www/html/test.pdf

Use browser to see if you can open it.

Use the values your query finds.

'SoS', Ken

In reply to Ken Task

Re: Error message "Cannot open the PDF. The file may be corrupt, or in an unsupported format."

by Sagar Mungse -

In my case /usr/bin/gs is perfect. I have checked hash value in Database and file name inside moodledata, both are same. As per your suggestion I have also opened same file in Edge, Chrome browsers.

Other Assignment and submissions are working perfect.

I dont understand why I am getting that error? Is there any configuration mistake from my side or Instructor made some mistake?

How can I find where exactly issue is?

Please help

Funny thing is I am getting error on  production server and testing server is perfect.😂

Awaiting to hear from you. 

In reply to Sagar Mungse

Re: Error message "Cannot open the PDF. The file may be corrupt, or in an unsupported format."

by Ken Task -
Picture of Particularly helpful Moodlers

@Sagar ... piggy backing on another what appears to be similar ... but maybe not *exactly* ... isn't a good idea ... but ...

Gee ... is there such a thing as a 'perfect' server?

Folks attempting to assist in these forums can only provide answers to questions if accurate info is shared ... but questions like 'understanding why ...' are beyond capabilities - can't do Vulcan Mind Melds remotely.

This ... "getting error on  production server and testing server is perfect" has to mean there is something different then, right?

And debugging set to developer level produces nothing?

'SoS', Ken

In reply to Ken Task

Re: Error message "Cannot open the PDF. The file may be corrupt, or in an unsupported format."

by Muhammad Baqar -
Hi folks,

I am new user of Moodle. I am facing the same issue of pdf viewer. I have also read your solutions and try all in my server but still no luck. I am currently using Moodle 3.9. I have also check it on previous versions like 3.8 but the problem persist.
In reply to Ken Task

Re: Error message "Cannot open the PDF. The file may be corrupt, or in an unsupported format."

by Swati Sharma -

Hi Ken,

Is it possible to call a ghostscript that is located on a different server than your moodle instance?

Thanks in advance

-Swati

In reply to Ken Task

Re: Error message "Cannot open the PDF. The file may be corrupt, or in an unsupported format."

by Fathur Rohman -

Hello All,

I encountered the same problem.

I have tried installing on local system, Ubuntu 20.04 Server, PHP 7.4.3, Ghostscript 9.50, everything works normally.

I  got error "Cannot open the PDF. The file may be corrupt, or in an unsupported format." when running moodle 3.9.2 on Shared Hosting.

It's an old RHEL 4.8.5-39, and as a user i get a jailshell and chrootjail, so i can't do anything. :D


However, the "system path" have been configured with ghostscript's path and other components, it's a green tick.


I've also checked that ghostscript is installed, even though it's not the latest version (it is 9.25, current latest 9.53.1)


And System environtment on my Shared Hosting Moodle look like normal:



is there any other way to check the cause of this problem?


Thanks,

Fathur

In reply to Fathur Rohman

Re: Error message "Cannot open the PDF. The file may be corrupt, or in an unsupported format."

by Emma Richardson -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers
What method are you using for document conversion? If not Google, I suggest switching...
In reply to Ken Task

Re: Error message "Cannot open the PDF. The file may be corrupt, or in an unsupported format."

by Heber Vazquez -

Hi everyone.

I have the same problem with the pdf in Moodle using RHEL 8 equivalent (Rocky).

In the logs see that:

/usr/bin/gs: /opt/lampp/lib/libtiff.so.5: no version information available (required by /lib64/libgs.so.9)
/usr/bin/gs: symbol lookup error: /lib64/libgs.so.9: undefined symbol: FT_Property_Set
/usr/bin/gs: /opt/lampp/lib/libtiff.so.5: no version information available (required by /lib64/libgs.so.9)
/usr/bin/gs: symbol lookup error: /lib64/libgs.so.9: undefined symbol: FT_Property_Set

aparently the ghostscript don´t recognize the version or the format of the PDF.

My version is  GPL Ghostscript 9.25 (2018-09-13).

Something new, about this error?


In reply to Heber Vazquez

Re: Error message "Cannot open the PDF. The file may be corrupt, or in an unsupported format."

by Ken Task -
Picture of Particularly helpful Moodlers

@Herber - you piggy-backed on a posting from 2019  Not good considering you have something much more 'modern'.  This to say, might be same error but for very different reasons.

Ok, we know Rocky Linux and I see a couple of things in your sharing of errors:

/opt/lampp/ ... is your AMP stack from native Rocky repo's or did you acquire something else?

the symbol lookup error lines ... actually all lines, are pointing to missing libraries that support GD - like libtiff.so.5 ... tiff is a font ... .so is a sharable object ... version 5?

So suggest using package manager on Rocky (dnf or yum) to see if there are libraries available for GD.

Maybe:

dnf list libtiff or some similar query of package manager.

Uhhh ... don't run Rocky but do run CentOS 7 still so maybe am not pointing you to the right place.

'SoS', Ken

In reply to Dave Weninger

Re: Error message "Cannot open the PDF. The file may be corrupt, or in an unsupported format."

by Juan Francisco Sandoval -

If it is of any use for someone.

In order for this feature to work Ghostscript needs to be properly enabled. @Ken Task gives proper instructions to do so: https://moodle.org/mod/forum/discuss.php?d=393936#p1588313

Now, besides that, you need to keep in mind that for Ghostscript to be called from the Moodle site, the PHP functions "exec" and "shellexec" need to be enabled serverwise. If not Moodle will not be able to use Ghostscript app at all.

In cPanel (if you have root access) you can do so from the WHM > MultiPHP Manager > Manage Settings > Scroll to "Disabled Functions" > Once there, make sure the "exec" and "shellexec" are not added and remove them if so > Press the Update button

Make sure to do that to the PHP version used by the Moodle site. Once done, you should be able to use Ghostscript properly and because of that, be able to use the "Annotations" feature.

Unfortunately I am not sure how to do it in servers using other software, but it should be somewhat similar.

Hope this saves some time to anyone.

PD: thanks to Charles Krengel, this answer is based on his input > https://moodle.org/mod/forum/discuss.php?d=388698#p1631401

Average of ratings: Useful (1)
In reply to Dave Weninger

Re: Error message "Cannot open the PDF. The file may be corrupt, or in an unsupported format."

by yexiang wu -

Dear All,

Thanks for all your efforts. May I ask if the solution can also be applied to my case? It looks the same, but there are still some differences.

Some files are corrupted when teacher are marking on annotation page, however, most submission are fine. Maybe these files are not supported format. Another questions is, teachers can download the file, but they can't save grades on this page (using rubric). Please check the following image:

grty

tr

We are using moodle 3.10. Hope anyone can provide some ideas.