Scripts pour Nautilus.
[progfou.git] / nautilus-scripts / Conversion PDF vers texte
CommitLineData
ec45958d
P
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3# Debian-Depends: poppler-utils (pdftotext)
4import sys
5from subprocess import Popen, PIPE
6
7if len(sys.argv) < 2:
8 sys.exit(0)
9
10for filename in sys.argv[1:]:
11 olddir = os.getcwd()
12 os.chdir(os.path.dirname(filename))
13 filename = os.path.basename(filename)
14 p1 = Popen(["/usr/bin/pdftotext", filename, "-"], stdout=PIPE)
15 p2 = Popen(["/bin/sed", "-e", "s|\t\r  | |g;s|-­‐|–|g;s| \+| |g"], stdin=p1.stdout, stdout=PIPE)
16 p1.stdout.close() # Allow p1 to receive a SIGPIPE if p2 exits.
17 output = p2.communicate()[0]
18 file(filename + '.txt', 'wt').write(output)
19 os.chdir(olddir)
20
21sys.exit(0)