Skip to content
This repository was archived by the owner on May 19, 2023. It is now read-only.

Commit f3ad31e

Browse files
committed
Convert PDF numbering to indexing from 0
1 parent 319c87c commit f3ad31e

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ I'm using a Windows executable generated with [`PyInstaller`](https://github.com
3636
Arguments `-s` and `-p` can be repeated as many times as needed, but both have to be repeated the same number of times.
3737
So if a file needs to be split into 3 new files, 3 file names will need to be specified, each one with `-s`, and also 3 page ranges with `-p`, respectively.
3838

39-
The page numbers start in 0.
40-
4139
### Examples
4240

4341
Assume this is the folder, and you're using the executable:
@@ -51,7 +49,7 @@ folder/
5149
Following the previous example, running this inside `folder/`:
5250

5351
```txt
54-
pdf-splitter -s DEGREE-BACH -s IDCARD -p 0 1 -p 2 2 1234.pdf
52+
pdf-splitter -s DEGREE-BACH -s IDCARD -p 1 2 -p 3 3 1234.pdf
5553
```
5654

5755
Will result in:

pdf-splitter/main.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,26 @@
2020
required=True,
2121
type=int,
2222
nargs=2,
23-
help='first and last page numbers to split from the input file'
23+
help='range of first and last page numbers to split from the input file, according to file numbering (first page is page 1)'
2424
)
2525

2626
args = parser.parse_args()
27-
print(args)
2827
if len(args.page_numbers) != len(args.split_name):
2928
raise argparse.ArgumentTypeError('specify the same number of page ranges as the number of splits.')
3029

3130
inputfile = InputFile(args.filepath)
32-
splits = [SplitFile(f'{name}.pdf', pages) for name, pages in zip(args.split_name, args.page_numbers)]
31+
splits = [
32+
SplitFile(f'{inputfile.id}-{name}.pdf', pages)
33+
for name, pages in zip(
34+
args.split_name,
35+
# PDF objects number pages starting in 0
36+
((first - 1, last - 1) for first, last in args.page_numbers)
37+
)
38+
]
39+
40+
# info in console
41+
print(f'Splitting {inputfile.name} into {len(splits)} new files...', flush=True)
3342
split_pdf(inputfile, splits)
43+
print(f'{len(splits)} files created:', flush=True)
44+
for split in splits:
45+
print(f' - {split.name}')

0 commit comments

Comments
 (0)