From e8e6eaf3ae79d19eb46cee814994605cfa7a5211 Mon Sep 17 00:00:00 2001 From: tssujt Date: Tue, 24 Jun 2025 22:36:52 +0800 Subject: [PATCH] Replace PyMuPDF with pypdf for PDF handling --- cbz/comic.py | 13 +++++-------- pyproject.toml | 4 ++-- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/cbz/comic.py b/cbz/comic.py index 7db6fc0..d004ff5 100644 --- a/cbz/comic.py +++ b/cbz/comic.py @@ -8,7 +8,7 @@ from io import BytesIO from typing import Union from pathlib import Path -import fitz +from pypdf import PdfReader import xmltodict from cbz.constants import XML_NAME, COMIC_FIELDS, IMAGE_FORMAT, PAGE_FIELDS @@ -98,13 +98,10 @@ class ComicInfo(ComicModel): ComicInfo: An instance of ComicInfo. """ pages: list[PageInfo] = [] - with fitz.open(path) as pf: - for element in pf: - # Check if the page has images - images = element.get_images(full=True) - for i, image in enumerate(images): - base = pf.extract_image(image[0]) - pages.append(PageInfo.loads(data=base['image'])) + reader = PdfReader(path) + for page in reader.pages: + for image in page.images: + pages.append(PageInfo.loads(data=image.data)) assert pages, 'No valid images present in file' return ComicInfo.from_pages(pages=pages) diff --git a/pyproject.toml b/pyproject.toml index 0af70a3..1fa3e14 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -34,7 +34,7 @@ python = ">=3.8" xmltodict = ">=0.13.0" langcodes = ">=3.4.0" Pillow = ">=10.4.0" -PyMuPDF = ">=1.24.7" +pypdf = ">=5.6.1" [tool.poetry.scripts] cbzplayer = "cbz.__main__:main" @@ -45,4 +45,4 @@ url = "https://pypi.org/simple/" priority = "primary" [certificates] -localpypi = { cert = false } \ No newline at end of file +localpypi = { cert = false }