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

Refactor: Explore replacing PikePDF with PyMuPDF for efficiency #252

Open
holtskinner opened this issue Feb 5, 2024 · 1 comment
Open

Comments

@holtskinner
Copy link
Member

Explore switching PDF Splitter from PikePDF to PyMuPDF

See if efficiency/code readability improves

https://pymupdf.readthedocs.io/en/latest/about.html

@holtskinner
Copy link
Member Author

Running this code for testing:

import timeit

from google.cloud.documentai_toolbox import document

document_json_path = "documentai_SampleDocuments_PROCUREMENT_DOCUMENT_SPLIT_PROCESSOR_pretrained-procurement-splitter-v1.2-2022-08-19_output.json"
document_pdf_path = "documentai_SampleDocuments_PROCUREMENT_DOCUMENT_SPLIT_PROCESSOR_procurement_multi_document.pdf"

doc = document.Document.from_document_path(document_json_path)

output_path = "/"

# Test the PikePDF function
pikepdf_time = timeit.timeit(lambda: doc.split_pdf(document_pdf_path, output_path), number=10)

# Test the PyMuPDF function
mupdf_time = timeit.timeit(lambda: doc.split_pdf_mupdf(document_pdf_path, output_path), number=10)

print(f"PikePDF Time: {pikepdf_time} seconds")
print(f"PyMuPDF Time: {mupdf_time} seconds")

print(f"difference is {pikepdf_time-mupdf_time} seconds")

Got this result

python pymupdf_test.py
PikePDF Time: 0.0616944160001367 seconds
PyMuPDF Time: 0.06151633399986167 seconds
difference is 0.00017808200027502608 seconds

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

No branches or pull requests

1 participant