Sunday, April 28, 2024
 Popular · Latest · Hot · Upcoming
3
rated 0 times [  3] [ 0]  / answers: 1 / hits: 6893  / 1 Year 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

 Answers
7

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 &

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

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

Location: Cape Verde
Member since Fri, Sep 16, 2022
2 Years ago
;