-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add with ... as ...
Usage to PdfMerger()
#1108
Comments
I like the idea! Do you want to create a pr? |
I'd like so, but as a middle school student in China, I am still busy even in summer vacation, but I will try my BEST! |
I noticed that from PyPDF2 import PdfMerger
with PdfMerger(strict=False, fileobj="./output.pdf") as merger:
for name in ["01.pdf", "02.pdf", "03.pdf", ...]:
merger.append(name) |
It will be like: from PyPDF2 import PdfWriter
with PdfWriter(fileobj="./output.pdf") as writer:
... # Do what you like to do. |
Please leave this open until the pr is merged |
Closes #1108 Closes #1117 Full credit for this PR goes to JianzhengLuo Co-authored-by: JianzhengLuo <[email protected]>
Explanation
As I need to call
write()
andclose()
inPdfMerger()
, why not add__enter__
and__exit__
method to it so I can use it more elegantly.Code Example
The text was updated successfully, but these errors were encountered: