Skip to content

Commit ec26dbd

Browse files
committed
Finished Background/Stamp functionality
1 parent 8e2c25d commit ec26dbd

2 files changed

Lines changed: 33 additions & 20 deletions

File tree

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,22 @@ PyPDF Builder is built on [Tkinter](https://docs.python.org/3/library/tk.html),
2323

2424
```
2525
pygubu==0.9.8.2
26+
PyInstaller==3.3.1
2627
PyPDF2==1.26.0
28+
Sphinx==1.7.2
2729
```
2830

31+
... and a whole bunch of related dependencies (especially Sphinx is a doozy!).
32+
2933
Python 3.6 was used in development… I haven't checked for compatibility with lower versions, so your mileage my vary with anything starting 3.5 on downward.
3034

35+
36+
## Deployment
37+
38+
Distributable application for Windows, Linux and Mac OS using pyInstaller or similiar tool. This isn't all too clear yet.
39+
40+
Long term: Inclusion in Debian repos for direct installation on end-user systems.
41+
3142
## License
3243

3344
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details
@@ -41,7 +52,8 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
4152
- [X] Join Tab Functionality
4253
- [X] Split Tab Functionality
4354
- [ ] Refactor to avoid code repetition in save, file info, etc methods
44-
- [ ] Documentation
55+
- [ ] User Documentation (mostly self-explanatory)
56+
- [ ] Developer Documentation
4557
- [ ] Write tests
4658
- [ ] Error checking user input
4759
- [ ] Error/Exception Handling

pypdfbuilder.py

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -77,25 +77,26 @@ def save_as(self):
7777
if self.__source_filepath and self.__bg_filepath:
7878
out_pdf = PdfFileWriter()
7979
command = self.__bg_command.get()
80-
for p in range(self.__source_pdf_pages):
81-
# new PdfFileReader instances needed for every page merged. See here:
82-
# https://github.com/mstamy2/PyPDF2/issues/100#issuecomment-43145634
83-
source_pdf = PdfFileReader(open(self.__source_filepath, "rb"))
84-
bg_pdf = PdfFileReader(open(self.__bg_filepath, "rb"))
85-
bg_page = bg_pdf.getPage(0)
86-
source_page = source_pdf.getPage(p)
87-
back_page = None
88-
front_page = None
89-
if command == 'STAMP':
90-
front_page = bg_page
91-
back_page = source_page
92-
elif command == 'BG':
93-
front_page = source_page
94-
back_page = bg_page
95-
back_page.mergePage(front_page)
96-
out_pdf.addPage(back_page)
97-
with open(save_filepath, "wb") as out_pdf_stream:
98-
out_pdf.write(out_pdf_stream)
80+
with open(self.__source_filepath, "rb") as source_pdf_stream, \
81+
open(self.__bg_filepath, "rb") as bg_pdf_stream:
82+
for p in range(self.__source_pdf_pages):
83+
# new PdfFileReader instances needed for every page merged. See here:
84+
# https://github.com/mstamy2/PyPDF2/issues/100#issuecomment-43145634
85+
source_pdf = PdfFileReader(source_pdf_stream)
86+
bg_pdf = PdfFileReader(bg_pdf_stream)
87+
if not self.__bg_only_first_page.get() or (self.__bg_only_first_page.get() and p < 1):
88+
if command == 'STAMP':
89+
top_page = bg_pdf.getPage(0)
90+
bottom_page = source_pdf.getPage(p)
91+
elif command == 'BG':
92+
top_page = source_pdf.getPage(p)
93+
bottom_page = bg_pdf.getPage(0)
94+
bottom_page.mergePage(top_page)
95+
else:
96+
bottom_page = source_pdf.getPage(p)
97+
out_pdf.addPage(bottom_page)
98+
with open(save_filepath, "wb") as out_pdf_stream:
99+
out_pdf.write(out_pdf_stream)
99100

100101

101102
class SplitTabManager:

0 commit comments

Comments
 (0)