Skip to content

Commit 04b93a4

Browse files
committed
added commandline arguments and updated the README.md
1 parent e04ee3e commit 04b93a4

File tree

2 files changed

+62
-9
lines changed

2 files changed

+62
-9
lines changed

README.md

+9
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,11 @@
11
# PDF-Scan-Merger
22
A little script that merges scanned pdf files together, if you scan two-sided documents with a single-sided sheet feed scanner.
3+
4+
This is written and tested with python3.
5+
To run the script, pdfrw and argparse must be installed.
6+
You get help by using the argument `-h`.
7+
Because the even pages will mostly be scanned in reverse order after you scanned the odd ones and turn the whole pile around, there is the `--evenrev` argument which reverses the even pages before shuffling them together. You can do this with odd pages (`--oddrev`), too.
8+
9+
In `examplefiles/` some example pdfs are provided to test the tool.
10+
11+
If you would like to have some additional features, feel free to contribute or create an issue.

combineScans.py

+53-9
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,68 @@
11
from pdfrw import PdfReader, PdfWriter, PageMerge
2+
import argparse
23

3-
even = PdfReader('examplefiles/even_rev.pdf')
4-
odd = PdfReader('examplefiles/odd.pdf')
5-
isEvenReversed = True;
4+
# Arguments
5+
parser = argparse.ArgumentParser(description='Process scanned pdf documents. It takes two files, one with the front and one of the back of each page and shuffles them together into one single document.')
6+
7+
parser.add_argument('oddFile',
8+
type = str,
9+
nargs=1,
10+
help='path to the pdf with all odd pages (starting from 1)',
11+
default='examplefiles/odd.pdf')
12+
13+
parser.add_argument('evenFile',
14+
type = str,
15+
nargs=1,
16+
help='path to the pdf with all even pages (starting from 2)',
17+
default='examplefiles/even_rev.pdf')
18+
19+
parser.add_argument('resultFile',
20+
type = str,
21+
nargs=1,
22+
help='path and name where the shuffled file should be stored',
23+
default='examplefiles/all.pdf')
24+
25+
parser.add_argument('--oddrev',
26+
dest='oddrev',
27+
action='store_const',
28+
const=True,
29+
default=False,
30+
help='reverses the odd pages before shuffling')
31+
32+
parser.add_argument('--evenrev',
33+
dest='evenrev',
34+
action='store_const',
35+
const=True,
36+
default=False,
37+
help='reverses the even pages before shuffling')
38+
39+
args = parser.parse_args()
40+
41+
# The shuffling magic
42+
even = PdfReader(args.evenFile[0])
43+
odd = PdfReader(args.oddFile[0])
44+
isEvenReversed = args.evenrev;
45+
isOddReversed = args.oddrev;
646
all = PdfWriter()
747
blank = PageMerge()
848
blank.mbox = [0, 0, 612, 792] # 8.5 x 11
949
blank = blank.render()
1050

11-
#all.addpage(blank)
12-
if isEvenReversed:
51+
if isEvenReversed and not isOddReversed:
1352
for i in range(0, len(odd.pages)):
1453
all.addpage(odd.pages[i])
1554
all.addpage(even.pages[len(even.pages)-1-i])
55+
elif isOddReversed and not isEvenReversed:
56+
for i in range(0, len(odd.pages)):
57+
all.addpage(odd.pages[len(odd.pages)-1-i])
58+
all.addpage(even.pages[i])
59+
elif isEvenReversed and isOddReversed:
60+
for i in range(0, len(odd.pages)):
61+
all.addpage(odd.pages[len(odd.pages)-1-i])
62+
all.addpage(even.pages[len(even.pages)-1-i])
1663
else:
1764
for x,y in zip(odd.pages, even.pages):
1865
all.addpage(x)
1966
all.addpage(y)
2067

21-
#while len(all.pagearray) % 2:
22-
# all.addpage(blank)
23-
24-
all.write('examplefiles/all.pdf')
68+
all.write(args.resultFile[0])

0 commit comments

Comments
 (0)