Last active
November 5, 2025 03:06
-
-
Save yuxincs/fd703fbb32774ddd2eb78365e375cc50 to your computer and use it in GitHub Desktop.
PDF to Images
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def _pdf_to_images_high_quality(pdf_path, dpi=200): | |
| images = [] | |
| with fitz.open(pdf_path) as pdf_document: | |
| zoom = dpi / 72.0 | |
| matrix = fitz.Matrix(zoom, zoom) | |
| for page_num in range(pdf_document.page_count): | |
| page = pdf_document[page_num] | |
| pixmap = page.get_pixmap(matrix=matrix, alpha=False) | |
| Image.MAX_IMAGE_PIXELS = None | |
| img_data = pixmap.tobytes("png") | |
| img = Image.open(io.BytesIO(img_data)) | |
| images.append(img) | |
| return images |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment