nautilus-scripts : correction d'un bogue + copyright/licence
[progfou.git] / nautilus-scripts / Conversion PDF vers texte
CommitLineData
ec45958d
P
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
f7647023
P
3# Copyright © 2014 AUF
4# Licence: GPL-2
5# Author: Progfou <jean-christophe.andre@auf.org>
6# Created: 2014-01-31
7# Debian-Depends: python (>= 2.6), poppler-utils (pdftotext)
ec45958d
P
8import sys
9from subprocess import Popen, PIPE
10
11if len(sys.argv) < 2:
12 sys.exit(0)
13
14for filename in sys.argv[1:]:
15 olddir = os.getcwd()
16 os.chdir(os.path.dirname(filename))
17 filename = os.path.basename(filename)
18 p1 = Popen(["/usr/bin/pdftotext", filename, "-"], stdout=PIPE)
19 p2 = Popen(["/bin/sed", "-e", "s|\t\r  | |g;s|-­‐|–|g;s| \+| |g"], stdin=p1.stdout, stdout=PIPE)
20 p1.stdout.close() # Allow p1 to receive a SIGPIPE if p2 exits.
21 output = p2.communicate()[0]
22 file(filename + '.txt', 'wt').write(output)
23 os.chdir(olddir)
24
25sys.exit(0)