Someone asked me today why they couldn't write on the DOCX document they received from a student using the pen in their Onyx Note Pro reader. The answer, of course, is that while the Onyx can read those files, it can't annotate them: that only works with PDFs.

Next question then, is of course: do I really need to open each file separately and save them as PDF? That's going to take forever, I have 30 students per class!

Fear not, shell scripting and headless mode flies in to the rescue!

As it turns out, one of the Libreoffice parameters allow you to run batch operations on files. By calling:

libreoffice --headless --convert-to pdf *.docx

LibreOffice will happily convert all the *.docx files in the current directory to PDF. But because navigating the commandline can be hard, I figured I could push this a tiny little bit further and wrote the following script:

#!/bin/sh

exec libreoffice --headless --convert-to pdf "$@"

Drop this in ~/.local/share/nautilus/scripts/libreoffice-pdf, mark it executable, and voilà! You can batch-convert basically any text file (or anything supported by LibreOffice, really) into PDF.

Now I wonder if this would be a useful addition to the Debian package, anyone?

Why not unoconv?
Is that not precisely the idea of unoconv? plus it converts to many other formats and handles the headless server very nicely...
Comment by Anonymous coward
alternatives

Is that not precisely the idea of unoconv? plus it converts to many other formats and handles the headless server very nicely...

unoconv, sure, why not. Someone also suggested lloconv. There's also Pandoc that could probably do this as well.

The thing is none of those have file manager integration. Plus, it's extra software to install. I want the simplest possible instructions, targeting novice Linux users, which means as little (commandline, in particular) work as possible. Installing new packages is therefore superfluous.

By the way, I suspect the above instructions I made do reuse existing Libreoffice instances if they are already running. I might be wrong, but it seems faster with than without...

Without LibreOffice running:

===> multitime results
1: libreoffice --headless --convert-to pdf impots.ods
            Mean        Std.Dev.    Min         Median      Max
real        1.726       0.061       1.671       1.695       1.876       
user        1.258       0.050       1.208       1.244       1.362       
sys         0.226       0.023       0.180       0.231       0.257

With LibreOffice running:

===> multitime results
1: libreoffice --headless --convert-to pdf impots.ods
            Mean        Std.Dev.    Min         Median      Max
real        0.411       0.033       0.367       0.398       0.468       
user        0.014       0.006       0.005       0.013       0.022       
sys         0.012       0.007       0.001       0.012       0.023

So thanks everyone for the recommendations, those are very useful tools! But I think LibreOffice's builtin commandline is fine for this purpose for now.

Comment by anarcat
Comments on this page are closed.
Created . Edited .