15673a28149d4b660b346c8d18b29c84290d1736
[progfou.git] / nautilus-scripts / Conversion PDF vers texte
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 # Debian-Depends: poppler-utils (pdftotext)
4 import sys
5 from subprocess import Popen, PIPE
6
7 if len(sys.argv) < 2:
8     sys.exit(0)
9
10 for 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
21 sys.exit(0)