Skip to content

Commit d7e652d

Browse files
committed
merge: tag '1.1.0' into develop
Better error handling when merging files and user interaction in this phase
2 parents 6c3f556 + 3aa8cc0 commit d7e652d

File tree

4 files changed

+44
-7
lines changed

4 files changed

+44
-7
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
data/
22
build/
33
dist/
4+
.spec
45
*.pdf
56
*.pyc

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@ This is a basic project to merge pdf files.
77
To get help, run:
88

99
```sh
10-
path/to/exe -h
10+
python -m pdf_merger -h
1111
```
1212

1313
You can use it like this:
1414

1515
```sh
16-
path/to/exe -d dir/with/pdf/files -o result/file.pdf
16+
python -m pdf_merger -d dir/with/pdf/files -o result/file.pdf
1717
```
1818

1919
Or using the long form:
2020

2121
```sh
22-
path/to/exe --directory dir/with/pdf/files --output result/file.pdf
22+
python -m pdf_merger --dir dir/with/pdf/files --output result/file.pdf
2323
```
2424

2525
> [!NOTE]

changelog.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
## **1.1.0**&emsp;<sub><sup>2024-07-20 (e37d7b607f61e70b27caf17aeb0918eea4db0ee5...5121c8390c5637cded459375869982d4bbfdee9d)</sup></sub>
2+
3+
### Features
4+
5+
- first version (e49d7ce4751fbaecef63cda4388eeb392ea01e40)
6+
- better error handling and user interaction when merge (c6191f25fbc199ad97dca496c1bbf178dfd24c20)
7+
8+
### Bug Fixes
9+
10+
- corrects the long form of the directory argument in example and command in examples (5121c8390c5637cded459375869982d4bbfdee9d)
11+
12+
### Merges
13+
14+
- branch 'release/1\.0\.0' (a4dea194f2faeea0d78fccad0f68601401a51f82)
15+
- tag '1\.0\.0' into develop (f0f5b8f992140cc68a556d6294e1ff2fb476c9dd)
16+
17+
### ? ? ?
18+
19+
- Initial commit (e37d7b607f61e70b27caf17aeb0918eea4db0ee5)
20+
21+
<br>
22+
23+

pdf_merger.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,25 @@ def pdf_files_in_directory(path: Path) -> Optional[list[Path]]:
2121

2222

2323
def merge_pdf_files(files: list[Path], result_path: Path):
24-
writer = PdfWriter()
24+
try:
25+
writer = PdfWriter()
2526

26-
for file in files:
27-
writer.merge(None, fileobj=PdfReader(file, True))
27+
for file in files:
28+
writer.merge(None, fileobj=PdfReader(file, True))
2829

29-
writer.write(result_path.with_suffix(PDF_SUFFIX))
30+
if result_path.with_suffix(PDF_SUFFIX).exists():
31+
response = input(
32+
f"The file {result_path.name}.pdf exists, do you want to overwrite? (y/N): "
33+
)
34+
35+
if response.lower() != "y":
36+
print("Operation canceled.")
37+
return
38+
39+
writer.write(result_path.with_suffix(PDF_SUFFIX))
40+
print('PDFs merged succesfully!')
41+
except Exception as e:
42+
print(f"Failed to merge: {e}")
3043

3144

3245
def main():

0 commit comments

Comments
 (0)