Skip to content
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

ENH: Allow password at constructor #910

Closed
wants to merge 4 commits into from

Conversation

pubpub-zz
Copy link
Collaborator

adding new optional parameter at PdfReader

pubpub-zz added 3 commits May 27, 2022 09:02
adding new optional parameter at PdfReader
@codecov
Copy link

codecov bot commented May 27, 2022

Codecov Report

Merging #910 (fd33ff0) into main (bbfd46c) will increase coverage by 0.15%.
The diff coverage is 100.00%.

❗ Current head fd33ff0 differs from pull request most recent head 54ccbbf. Consider uploading reports for the commit 54ccbbf to get more accurate results

@@            Coverage Diff             @@
##             main     #910      +/-   ##
==========================================
+ Coverage   77.81%   77.96%   +0.15%     
==========================================
  Files          16       16              
  Lines        4327     4321       -6     
  Branches      812      815       +3     
==========================================
+ Hits         3367     3369       +2     
+ Misses        788      780       -8     
  Partials      172      172              
Impacted Files Coverage Δ
PyPDF2/_reader.py 77.25% <100.00%> (+0.23%) ⬆️
PyPDF2/xmp.py 52.06% <0.00%> (ø)
PyPDF2/generic.py 77.90% <0.00%> (+0.12%) ⬆️
PyPDF2/_page.py 79.95% <0.00%> (+0.57%) ⬆️
PyPDF2/_utils.py 90.99% <0.00%> (+1.33%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7647ab5...54ccbbf. Read the comment docs.

@MartinThoma
Copy link
Member

Thank you for the PR ❤️

I can see where you're coming from / why you added it. I thought about this a couple of times myself as well.

I'm torn between two philosophies here:

  1. Keep interfaces minimal / avoid "parameter creep"
  2. It might be pretty useful / more intuitive than the decrypt method (I have no intention to remove decrypt; it seems just like a valuable addition).

Looking at similar libraries:

  • Fitz/PyMuPDF: doc.authenticate(password) seems to be the only option
  • pdfrw: no decryption capabilities?
  • pikepdf: I couldn't figure out how to decrypt ... it must have those capabilities, though

What is your opinion @MasterOdin ?

@MasterOdin
Copy link
Member

@MartinThoma pikepdf offers a password parameter on its pikepdf.Pdf.open method which is decently synonymous with doing PyPDF.PdfReader().

I'm guessing that most people will always want to decrypt a PDF that's being read in before doing any other operations, I feel like baking it into the constructor makes sense.

MartinThoma added a commit that referenced this pull request May 29, 2022
This is a convenience change. You can still call `reader = PdfReader("encrypted.pdf"); reader.decrypt(password)`.

Full credit to pubpub-zz; I just made stylistic changes.

Closes #910 

Co-authored-by: pubpub-zz <[email protected]>
@MartinThoma
Copy link
Member

MartinThoma commented May 29, 2022

I made a few stylistic changes / applied black so that CI suceeds. The PR was merged with #920 / c59224a and will be part of the 2.0.0 release.

Thank you for your contribution!

@pubpub-zz pubpub-zz deleted the OpenWithPwd branch August 8, 2022 06:56
@MartinThoma MartinThoma changed the title Enh : allow password at constructor ENH: Allow password at constructor Feb 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants