Closed
Description
Describe the bug (mandatory)
When trying to combine two pdfs; I receive the following exception: RuntimeError: source object number out of range
doc.insertPDF(existing_doc)
File "/dev-test-scripts/pdfenv/lib/python2.7/site-packages/fitz/fitz.py", line 4093, in insertPDF
val = _fitz.Document_insertPDF(self, docsrc, from_page, to_page, start_at, rotate, links, annots, show_progress, final, _gmap)
RuntimeError: source object number out of range
To Reproduce (mandatory)
I simply load two pdfs and try combine them. It works for 99% of pdfs but for a few i hit this issue and trying figure if there is a way to detect that there will be an issue before trying to merge.
o_doc = open(other_pdf_name, "rb").read()
u_doc = open(existing_pdf_name, "rb").read()
other_doc = fitz.Document('pdf', o_doc)
existing_doc = fitz.Document('pdf', u_doc)
other_doc.insertPDF(existing_doc)
I tried loading the PDFs directly using fitz.Document(<filename>)
, but get the same results. I could even send you the PDF.
Expected behavior (optional)
I expect the method to be successful.
Your configuration (mandatory)
- MacOS, Catalina 10.15.7
- Python2.7 (ill try it on Python3 version to confirm)
- Whl from releases page. 1.18.3
Let me know if you want me to send the PDF that is breaking. Perhaps there is a method i could use to determine that the PDF is incompatible.