Unoconv not converting jpeg to PDF

Unoconv not converting jpeg to PDF

by Kristaps Muižnieks -
Number of replies: 8

Good day! 

I have noticed that our Moodle is not converting jpeg files to PDF. Just shows an empty page, blank page, also having yellow notification "Some of the files in this submission can only be accessed by direct download."

We have unoconv and the path is fine also other extensions works fine such as png and jpg.

Strange is that under document convertors I don't see this extension within the list of supported extensions.

Our moodle version: Moodle 3.7.1+ (Build: 20190718)

Unoconv version: 0.7

LibreOffice: 6.0.7.3

Attachment moodle unoconv.png
Average of ratings: Useful (1)
In reply to Kristaps Muižnieks

Atbilde: Unoconv not converting jpeg to PDF

by Kristaps Muižnieks -
Also tried this discussion by adding statement to manually change extension for file but that caused crash.

https://moodle.org/mod/forum/discuss.php?d=359535

Also we are using Apache.
In reply to Kristaps Muižnieks

Re: Atbilde: Unoconv not converting jpeg to PDF

by Ken Task -
Picture of Particularly helpful Moodlers

unoconv doesn't support .jpeg ... but does support .jpg

.jpeg files are not .jpg's.

So ... you could try the following ...

Use the following mysql query to find where these .jpeg files are located in
the sea of files in moodledata/filedir/

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

The contenthash value can be used to find the file in moodledata/filedir/
from command line.

cd /path/to/moodledata/filedir/
find ./ -name [contenthash]

That will take some time to run but one will see something like:
/xx/yy/contenthash

To make sure it's the right mime type:

file -b /xx/yy/contenthash

Ok, now the tricky parts ....

*copy* the /xx/yy/contenthash out of moodledata/filedir/ and put that copy
out to a web accessible directory (in this example, /var/www/html/img2convert/

cp /xx/yy/contenthash /var/www/html/img2convert/[filename].jpeg

Download and use local app to convert to .jpg

Or if you have imagemagick installed could try:

convert filename.jpeg filename.jpg

Upload the converted [filename].jpg to /var/www/html/imgconverted/

Or if imagemagick worked, cp the converted .jpg using below

From /var/www/html/imgconverted/ directory copy and replace the old contenthash name file:

cp [filename].jpg /path/to/moodledata/filedir//xx/yy/contenthash

From /var/www/html/imgconverted/ directory copy and replace the old contenthash name file:

cp [filename].jpg /path/to/moodledata/filedir//xx/yy/contenthash

In the DB mdl_files change filename from .jpeg to .jpg

now go to whatever to see if assignment can convert the file to pdf.

Fingers crossed!

'SoS', Ken

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

Atbilde: Re: Atbilde: Unoconv not converting jpeg to PDF

by Kristaps Muižnieks -
Hey!

Thanks for reply. This seems long way but must be tried.

So the only way to deal with jpegs is to restrict uploads by restricting students to upload non jpeg pictures? I have seen that there was some trick in old version of Moodle by changing file extension in the core files.
In reply to Kristaps Muižnieks

Re: Atbilde: Re: Atbilde: Unoconv not converting jpeg to PDF

by Ken Task -
Picture of Particularly helpful Moodlers

If you'll check assigment set up there is a mimetype (filestype) restriction one can set.   Students can only upload those.   No .jpeg for obvious reasons.

'some trick' that was then, cause just changing a file name extension doesn't change internals of a file ... any file ... any operating system ... any application.

'SoS', Ken

In reply to Kristaps Muižnieks

Re: Unoconv not converting jpeg to PDF

by Ha Lee -
In reply to Ha Lee

Re: Unoconv not converting jpeg to PDF

by Ken Task -
Picture of Particularly helpful Moodlers

Hopefully, you have command line access to your server.

IF you do, what does the following commands show?

/usr/bin/unoconv --version

/usr/bin/unoconv --show

On the server am using to explore this issue, mine shows a section

The following list of graphics formats are currently available:

  bmp      - Windows Bitmap [.bmp]
  emf      - Enhanced Metafile [.emf]
  eps      - Encapsulated PostScript [.eps]
  fodg     - OpenDocument Drawing (Flat XML) [.fodg]
  gif      - Graphics Interchange Format [.gif]
  html     - HTML Document (OpenOffice.org Draw) [.html]
  jpg      - Joint Photographic Experts Group [.jpg]
  met      - OS/2 Metafile [.met]
  odd      - OpenDocument Drawing [.odd]
  otg      - OpenDocument Drawing Template [.otg]
  pbm      - Portable Bitmap [.pbm]
  pct      - Mac Pict [.pct]
  pdf      - Portable Document Format [.pdf]
  pgm      - Portable Graymap [.pgm]
  png      - Portable Network Graphic [.png]
  ppm      - Portable Pixelmap [.ppm]
  ras      - Sun Raster Image [.ras]
  std      - OpenOffice.org 1.0 Drawing Template [.std]
  svg      - Scalable Vector Graphics [.svg]
  svm      - StarView Metafile [.svm]
  swf      - Macromedia Flash (SWF) [.swf]
  sxd      - OpenOffice.org 1.0 Drawing [.sxd]
  sxd3     - StarDraw 3.0 [.sxd]
  sxd5     - StarDraw 5.0 [.sxd]
  sxw      - StarOffice XML (Draw) [.sxw]
  tiff     - Tagged Image File Format [.tiff]
  vor      - StarDraw 5.0 Template [.vor]
  vor3     - StarDraw 3.0 Template [.vor]
  wmf      - Windows Metafile [.wmf]
  xhtml    - XHTML [.xhtml]
  xpm      - X PixMap [.xpm]

So what if, you renamed a .jpeg file and changed extension to .jpg

[root@server ~]# /usr/bin/soffice --version
LibreOffice 5.3.6.1 30(Build:1)

'SoS', Ken

Average of ratings: Useful (2)
In reply to Kristaps Muižnieks

Re: Unoconv not converting jpeg to PDF

by Nadav Kavalerchik -
Picture of Core developers Picture of Plugin developers Picture of Testers Picture of Translators
Here is a simple fix I made to unoconv (hope they integrate the PR I sent) that solved this issue for me:
https://github.com/unoconv/unoconv/issues/560
Average of ratings: Useful (1)