-
Notifications
You must be signed in to change notification settings - Fork 665
Open
Description
Description of the bug
I tried to delete pages using delete_pages() but it seems to not have effect when calling tobytes().
I cannot use insert_pdf() to create a new document without the pages as well because of the problem below:
#3315
How to reproduce the bug
>>> import pymupdf
>>> with open("Marco_Aurelio_Meditaciones_02_pages.pdf", "rb") as f:
... pdf_content = f.read()
...
>>> file_copy = pymupdf.open("pdf", pdf_content)
>>> page_to_keep = 0
>>> pages_to_delete = [i for i in range(len(file_copy)) if i != page_to_keep]
>>> file_copy.delete_pages(pages_to_delete)
>>> print(f"After deletion: {len(file_copy)} pages")
After deletion: 1 pages
>>> result_bytes = file_copy.tobytes()
>>> result_doc = pymupdf.open("pdf", result_bytes)
>>> print(f"Result document has {len(result_doc)} pages")
Result document has 2 pages
This is the document:
Marco_Aurelio_Meditaciones_02_pages.pdf
PyMuPDF version
1.26.3
Operating system
Linux
Python version
3.11
pappacena
Metadata
Metadata
Assignees
Labels
No labels