Auto convert odt to pdf
Solution 1
A quick and dirty example using code from the pyinotify project [http://github.com/seb-m/pyinotify]
You will need to change the WATCHED_DIR to your directory containing ODT files. Also remember to install unoconv first.
# Notifier example from tutorial
#
# See: http://github.com/seb-m/pyinotify/wiki/Tutorial
#
# odtwatcher.py
import os
import pyinotify
import subprocess
WATCHED_DIR = '/tmp/test'
wm = pyinotify.WatchManager() # Watch Manager
mask = pyinotify.IN_MODIFY
class EventHandler(pyinotify.ProcessEvent):
def process_IN_MODIFY(self, event):
fname = event.pathname
if os.path.splitext(fname)[1] == '.odt':
print 'MODIFIED: ', fname
args = ['unoconv', '-f', 'pdf', fname]
try:
subprocess.Popen(args)
except OSError as e:
print 'Could not convert file %s to PDF. Error %s' % (fname, str(e))
if __name__ == '__main__':
handler = EventHandler()
notifier = pyinotify.Notifier(wm, handler)
wdd = wm.add_watch(WATCHED_DIR, mask, rec=True)
notifier.loop()
Save this as odtwatcher.py and then run it in the background
python odtwatcher.py &
Solution 2
Try this extension (works well with LibreOffice on Gnome-Shell/Quantal) :
MultiSave enables you to save simultaneoulsly a document in the OpenDocument, MS Office and/or PDF formats as you choose.
MultiFormatSave is a new updated fork of MultiSave designed to work better with recent revisions of Libreoffice:
MultiFormatSave enables you to save simultaneously a document in the OpenDocument, MS Office and/or PDF formats as you choose for Writer, Calc or Impress
Forked from the starXpert MultiSave-extension
Make sure to choose the appropriate release for your LibreOffice version, e.g. 1.3.2 for LO 3.5 and 3.6.
Solution 3
You can also run libreoffice from the command line for your purpose. This gives you the advantage of batch conversion, but single files are also possible. This example converts all ODT files in the current directory to PDF:
libreoffice --headless --convert-to pdf *.odt
Get more information on command line options with:
man libreoffice
Solution 4
This post explains how to convert odt to pdf from the command-line very simply using CUPS.
http://www.yamamoto.com.ar/blog/?p=50
You can actually batch convert all the odt to pdf from a directory so this would actually save you from having to remember to export to pdf each single time!
Hope this helps!
Related videos on Youtube
Gautam
I am a coding enthusiast who is in love with the Linux Operating system. My Favorite Languages are Compiled : Its a Close tie between Java,Scala,Clojure and C Interpreted : This was until recently Headed by Python but now Ruby & JavaScript is proving to be good competitor.
Updated on September 18, 2022Comments
-
Gautam over 1 year
I am creating a few documents in Libre office and I have to always send them as
.pdf
.but each and every time I forget to export it as pdf , So is there any way to auto convert the
.odt
document intopdf
every time I save the document ?I have only about 4 docs , I keep making changes on them , So each and every time I make a change and save the
odt
I need that change to be updated in the corresponding pdf file .Ps : I understand that
unoconv
can be used to convert via command line but is there a way to automatically do it ?Another Ps : I found out that there is something called inotify and inotify-tools and that can be used to trigger events when a file changes . But I have no idea on how to use it .
-
somasekhar over 12 yearsYou could create a little bash script that does it for you. But you are looking for a way to let LibreOffice to the work?
-
Gautam over 12 yearsI actually don't mind how it works whether through a bash script or through LibreOffice as long as it works
-
-
Gautam over 12 yearsI think you have misinterpreted my question ,I have only about 4 docs , but I keep making changes on them , So each and every time I make a change and save I need that change to be updated in the corresponding pdf file .