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

Migrate from PyPDF2 to pypdf #199

Open
MartinThoma opened this issue Jan 31, 2023 · 8 comments
Open

Migrate from PyPDF2 to pypdf #199

MartinThoma opened this issue Jan 31, 2023 · 8 comments

Comments

@MartinThoma
Copy link

I'm the maintainer of pypdf and PyPDF2.

In 2022, I've decided to move the projects back together. Now development continues at pypdf (all lowercase). PyPDF2 will not receive any updates or bugfixes.

pypdf==3.1.0 is essentially the same as PyPDF2==3.0.0. However, I've noticed that you are probably only compatible with PyPDF2<2.0.0 (or <3.0.0, depending if you would accept deprecation warnings). The migration is mostly renamings, e.g. (PdfFileReader -> PdfReader, and using snake_case instead of camelCase for methods). See https://pypdf.readthedocs.io/en/latest/user/migration-1-to-2.html

Are you open to make the move?

@dragotin
Copy link
Owner

dragotin commented Feb 5, 2023

Yes, of course, thank you for letting me know.

Let's leave this open until I migrated, or in case I have a question ;-)

@MartinThoma
Copy link
Author

Hey! Is there an update to this?

@dragotin
Copy link
Owner

Hm, I was not considering it urgent. I am interested to have packages in the linux distros for pypdf but these are still mostly on pyPDF2 as it seems. My favorite distro openSUSE does not seem to have a pypdf package yet at all.

Is there a way to use pypdf and pyPDF2 alternatively - somehow with a fallback to pyPDF2 if pypdf was not found? I'd appreciate a bit of advise since I am not sooo deep in python.

@MartinThoma
Copy link
Author

MartinThoma commented Mar 26, 2023

pypdf == 3.1.0 is almost the same as PyPDF2 == 3.0.x, so you could do this:

try:
    from pypdf import PdfReader, PdfWriter  # or whatever you need
except ImportError:
    # use the PyPDF2 package if the pypdf package is not present
    from PyPDF2 import PdfReader, PdfWriter  # or whatever you need

@dragotin
Copy link
Owner

dragotin commented May 9, 2023

Thanks, I now tried that.

Unfortunately, it does not seem to be that easy: I get a lot of deprecations such as:

pypdf.errors.DeprecationError: addPage is deprecated and was removed in pypdf 3.0.0. Use add_page instead.

It seems to me that this requires a complete rewrite of the scripts with little chance to use one-for-both, or do I miss someting?

@dragotin
Copy link
Owner

see branch use_pypdf

@MartinThoma
Copy link
Author

It seems to me that this requires a complete rewrite of the scripts with little chance to use one-for-both, or do I miss someting?

All changes are naming changes and should be easy to apply.

You can write code that works with PyPDF2>=2.x and pypdf>=3.0.0 - you just need to have a fallback for the import.

But yes, you might need a lot of tiny changes.

@Shijuchintu
Copy link

Even I have the same problem. After the recent deprecation of pypdf we are unable to read it using PHP. If any one facing the same problem please help us to resolve.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants