Tuesday, September 26, 2023
 Popular · Latest · Hot · Upcoming
rated 0 times [  3] [ 0]  / answers: 1 / hits: 6800  / 8 Months ago, mon, february 20, 2023, 2:01:10

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 into pdf 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 .

More From » libreoffice


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]
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)

Save this as odtwatcher.py and then run it in the background

python odtwatcher.py &

[#43089] Tuesday, February 21, 2023, 8 Months  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.

Total Points: 292
Total Questions: 106
Total Answers: 115

Location: Cape Verde
Member since Fri, Sep 16, 2022
1 Year ago
ormlai questions
Wed, Sep 28, 22, 00:17, 1 Year ago
Sun, Aug 7, 22, 22:05, 1 Year ago
Wed, Jun 16, 21, 03:50, 2 Years ago
Sun, Feb 6, 22, 09:11, 2 Years ago
Mon, Jul 12, 21, 10:00, 2 Years ago